Remove mutation of documents in write_documents() (#231)

This commit is contained in:
Tanay Soni 2020-07-15 13:10:52 +02:00 committed by GitHub
parent e1d64c2c68
commit 4e10a1520d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -125,16 +125,22 @@ class ElasticsearchDocumentStore(BaseDocumentStore):
should be changed to what you have set for self.text_field and self.name_field .
:return: None
"""
documents_to_index = []
for doc in documents:
doc["_op_type"] = "create"
doc["_index"] = self.index
_doc = {
"_op_type": "create",
"_index": self.index,
**doc
} # type: Dict[str, Any]
# In order to have a flat structure in elastic + similar behaviour to the other DocumentStores,
# we "unnest" all value within "meta"
if "meta" in doc.keys():
for k, v in doc["meta"].items():
doc[k] = v
del doc["meta"]
bulk(self.client, documents, request_timeout=300)
if "meta" in _doc.keys():
for k, v in _doc["meta"].items():
_doc[k] = v
documents_to_index.append(_doc)
bulk(self.client, documents_to_index, request_timeout=300)
def get_document_count(self, index: Optional[str] = None,) -> int:
if index is None: