Skip to content

Commit

Permalink
Update es.py
Browse files Browse the repository at this point in the history
  • Loading branch information
zcqian committed Nov 2, 2021
1 parent e518ed6 commit a784de4
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions biothings/utils/es.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def create_index(self, mapping=None, extra_settings=None):
# if the remote server is of elasticsearch version 7 or later
# drop the doc_type first level key as it is no longer supported
self._populate_es_version()
if self._es_version > 6:
if self._host_major_ver > 6:
if len(mapping) == 1 and next(iter(mapping)) not in ('properties', 'dynamic', '_meta'):
mapping = next(iter(mapping.values()))

Expand Down Expand Up @@ -261,7 +261,7 @@ def _get_bulk(doc):
"_type": doc_type,
"_op_type": action,
})
if self._es_version > 6:
if self._host_major_ver > 6:
ndoc.pop("_type")
return ndoc
actions = (_get_bulk(doc) for doc in docs)
Expand Down Expand Up @@ -319,13 +319,21 @@ def update_docs(self, partial_docs, upsert=True, step=None, **kwargs):
step = step or self.step

def _get_bulk(doc):
doc = {
'_op_type': 'update',
"_index": index_name,
"_type": doc_type,
"_id": doc['_id'],
"doc": doc
}
if self._host_major_ver >= 7:
doc = {
'_op_type': 'update',
"_index": index_name,
"_id": doc['_id'],
"doc": doc
}
else:
doc = {
'_op_type': 'update',
"_index": index_name,
"_type": doc_type,
"_id": doc['_id'],
"doc": doc
}
if upsert:
doc['doc_as_upsert'] = True
return doc
Expand Down Expand Up @@ -467,6 +475,8 @@ def clean_field(self, field, dryrun=True, step=5000):
step is the size of bulk update on ES
try first with dryrun turned on, and then perform the actual updates with dryrun off.
'''
if self._host_major_ver >= 7:
raise RuntimeError("clean_field is no longer supported")
q = {
"query": {
"constant_score": {
Expand Down

0 comments on commit a784de4

Please sign in to comment.