Skip to content

Commit

Permalink
fix creator and contact
Browse files Browse the repository at this point in the history
  • Loading branch information
Li committed Oct 28, 2020
1 parent c28b27f commit 69cbd7b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 41 deletions.
6 changes: 3 additions & 3 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ def get_uuids_from_es(index):
def reindex_all_uuids(indexer, token):
with app.app_context():
try:
# remove entities that not in neo4j
# 1. remove entities that not in neo4j
neo4j_uuids = get_uuids_from_neo4j()
neo4j_uuids = set(neo4j_uuids)
es_uuids = []
Expand All @@ -376,14 +376,14 @@ def reindex_all_uuids(indexer, token):
indexer.delete(uuid)

donor_uuids = get_donor_uuids_from_neo4j()
# Multi-thread index entitiies
# 2. Multi-thread index entitiies
with concurrent.futures.ThreadPoolExecutor() as executor:
results = [executor.submit(indexer.reindex, uuid) for uuid
in donor_uuids]
for f in concurrent.futures.as_completed(results):
app.logger.debug(f.result())

# index collection
# 3. index collection
indexer.index_collections(token)
app.logger.info("###Reindex Live is Done###")
except Exception as e:
Expand Down
65 changes: 29 additions & 36 deletions src/elasticsearch/indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,54 +116,47 @@ def index_collections(self, token):
for index, configs in self.indices.items():
configs = IndexConfig(*configs)
if (
configs.access_level == HubmapConst.ACCESS_LEVEL_CONSORTIUM
configs.access_level == 'consortium'
and configs.doc_type == 'original'
):
# Consortium Collections #
index = 'hm_consortium_entities'
rspn = requests.get(
self.entity_webservice_url + "/collections",
headers={"Authorization": f"Bearer {token}"})
if not rspn.ok:
if rspn.status_code == 401:
raise ValueError("Token is not valid.")
else:
raise Exception("Something wrong with entity-api.")

hm_collections = rspn.json()

for collection in hm_collections:
self.add_datasets_to_collection(collection)
self.entity_keys_rename(collection)
collection.setdefault('entity_type', 'collection')
(self.eswriter
.write_or_update_document(index_name=index,
doc=json.dumps(collection),
uuid=collection['uuid']))
if (
elif (
configs.access_level == HubmapConst.ACCESS_LEVEL_PUBLIC
and configs.doc_type == 'original'
):
# Public Collections #
index = 'hm_public_entities'
rspn = requests.get(self.entity_webservice_url +
"/collections")
if not rspn.ok:
if rspn.status_code == 401:
raise ValueError("Token is not valid.")
else:
raise Exception("Something wrong with entity-api.")

hm_collections = rspn.json()

for collection in hm_collections:
self.add_datasets_to_collection(collection)
self.entity_keys_rename(collection)
collection.setdefault('entity_type', 'collection')
(self.eswriter
.write_or_update_document(index_name=index,
doc=json.dumps(collection),
uuid=collection['uuid']))
else:
continue

if not rspn.ok:
if rspn.status_code == 401:
raise ValueError("Token is not valid.")
else:
raise Exception("Something wrong with entity-api.")

hm_collections = rspn.json()

for collection in hm_collections:
self.add_datasets_to_collection(collection)
self.entity_keys_rename(collection)
collection.setdefault('entity_type', 'Collection')
(self.eswriter
.write_or_update_document(index_name=index,
doc=json.dumps(collection),
uuid=collection['uuid']))

prefix0, prefix1, _ = index.split("_")
index = f"{prefix0}_{prefix1}_portal"
transformed = json.dumps(transform(collection))
(self.eswriter
.write_or_update_document(index_name=index,
doc=transformed,
uuid=collection['uuid']))

def reindex(self, uuid):
try:
Expand Down
4 changes: 2 additions & 2 deletions src/elasticsearch/neo4j-to-es-attributes.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
},
"contacts": {
"es_name": "contacts",
"is_json_stored_as_text": false
"is_json_stored_as_text": true
},
"creators": {
"es_name": "creators",
"is_json_stored_as_text": false
"is_json_stored_as_text": true
},
"description": {
"es_name": "description",
Expand Down

0 comments on commit 69cbd7b

Please sign in to comment.