def create_optimade_index(self) -> None: """Load or create an index that can handle aliased OPTIMADE fields and attach it to the current client. """ body = self.predefined_index.get(self.name) if body is None: body = self.create_elastic_index_from_mapper( self.resource_mapper, self.all_fields ) properties = {} for field in list(body["mappings"]["doc"]["properties"].keys()): properties[self.resource_mapper.get_backend_field(field)] = body[ "mappings" ]["doc"]["properties"].pop(field) body["mappings"]["doc"]["properties"] = properties self.client.indices.create(index=self.name, body=body, ignore=400) LOGGER.debug(f"Created Elastic index for {self.name!r} with body {body}")
def load_entries(endpoint_name: str, endpoint_collection: MongoCollection): LOGGER.debug("Loading test %s...", endpoint_name) endpoint_collection.collection.insert_many(getattr(data, endpoint_name, [])) if endpoint_name == "links": LOGGER.debug( " Adding Materials-Consortia providers to links from optimade.org" ) providers = get_providers() for doc in providers: endpoint_collection.collection.replace_one( filter={"_id": ObjectId(doc["_id"]["$oid"])}, replacement=bson.json_util.loads(bson.json_util.dumps(doc)), upsert=True, ) LOGGER.debug("Done inserting test %s!", endpoint_name)
def load_entries(endpoint_name: str, endpoint_collection: EntryCollection): LOGGER.debug("Loading test %s...", endpoint_name) endpoint_collection.insert(getattr(data, endpoint_name, [])) if (CONFIG.database_backend.value in ("mongomock", "mongodb") and endpoint_name == "links"): LOGGER.debug( "Adding Materials-Consortia providers to links from optimade.org" ) providers = get_providers(add_mongo_id=True) for doc in providers: endpoint_collection.collection.replace_one( filter={"_id": ObjectId(doc["_id"]["$oid"])}, replacement=bson.json_util.loads( bson.json_util.dumps(doc)), upsert=True, ) LOGGER.debug("Done inserting test %s!", endpoint_name)
This specification is generated using [`optimade-python-tools`](https://github.com/Materials-Consortia/optimade-python-tools/tree/v{__version__}) v{__version__}.""" ), version=__api_version__, docs_url=f"{BASE_URL_PREFIXES['major']}/extensions/docs", redoc_url=f"{BASE_URL_PREFIXES['major']}/extensions/redoc", openapi_url=f"{BASE_URL_PREFIXES['major']}/extensions/openapi.json", ) if not CONFIG.use_real_mongo and CONFIG.index_links_path.exists(): import bson.json_util from bson.objectid import ObjectId from optimade.server.routers.links import links_coll from optimade.server.routers.utils import mongo_id_for_database, get_providers LOGGER.debug("Loading index links...") with open(CONFIG.index_links_path) as f: data = json.load(f) processed = [] for db in data: db["_id"] = {"$oid": mongo_id_for_database(db["id"], db["type"])} processed.append(db) LOGGER.debug(" Inserting index links into collection from %s...", CONFIG.index_links_path) links_coll.collection.insert_many( bson.json_util.loads(bson.json_util.dumps(processed))) LOGGER.debug( " Adding Materials-Consortia providers to links from optimade.org...")