forked from ourresearch/openalex-guts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbulk_actions.py
More file actions
27 lines (22 loc) · 835 Bytes
/
bulk_actions.py
File metadata and controls
27 lines (22 loc) · 835 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import datetime
from app import logger
from util import entity_md5
def create_bulk_actions(entity, index_name):
bulk_actions = []
my_dict = entity.to_dict()
my_dict['updated'] = my_dict.get('updated_date')
my_dict['@timestamp'] = datetime.datetime.utcnow().isoformat()
new_entity_hash = entity_md5(my_dict)
old_entity_hash = entity.json_entity_hash
if new_entity_hash != old_entity_hash:
logger.info(f"dictionary for {entity.id} new or changed, so save again")
index_record = {
"_op_type": "index",
"_index": index_name,
"_id": entity.id,
"_source": my_dict
}
bulk_actions.append(index_record)
else:
logger.info(f"dictionary not changed, don't save again {entity.id}")
return bulk_actions, new_entity_hash