Skip to content

Commit

Permalink
update bulk delete syntax for ES7+
Browse files Browse the repository at this point in the history
  • Loading branch information
zcqian committed Nov 1, 2021
1 parent b6157ae commit e518ed6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions biothings/hub/databuild/syncer.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,7 @@ def sync_es_jsondiff_worker(diff_file,

# delete: remove from "old"
for ids in iter_n(diff["delete"], batch_size):
# FIXME: bulk delete can fail
del_skip = indexer.delete_docs(ids)
res["deleted"] += del_skip[0]
res["skipped"] += del_skip[1]
Expand Down
19 changes: 13 additions & 6 deletions biothings/utils/es.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,19 @@ def delete_docs(self, ids, step=None):
step = step or self.step

def _get_bulk(_id):
doc = {
'_op_type': 'delete',
"_index": index_name,
"_type": doc_type,
"_id": _id
}
if self._host_major_ver >= 7:
doc = {
'_op_type': 'delete',
"_index": index_name,
"_id": _id
}
else:
doc = {
'_op_type': 'delete',
"_index": index_name,
"_type": doc_type,
"_id": _id
}
return doc
actions = (_get_bulk(_id) for _id in ids)
return helpers.bulk(self._es, actions, chunk_size=step, stats_only=True, raise_on_error=False)
Expand Down

0 comments on commit e518ed6

Please sign in to comment.