mirror of
https://github.com/deepset-ai/haystack.git
synced 2025-09-27 00:53:58 +00:00
Remove mutation of documents in write_documents() (#231)
This commit is contained in:
parent
e1d64c2c68
commit
4e10a1520d
@ -125,16 +125,22 @@ class ElasticsearchDocumentStore(BaseDocumentStore):
|
|||||||
should be changed to what you have set for self.text_field and self.name_field .
|
should be changed to what you have set for self.text_field and self.name_field .
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
documents_to_index = []
|
||||||
for doc in documents:
|
for doc in documents:
|
||||||
doc["_op_type"] = "create"
|
_doc = {
|
||||||
doc["_index"] = self.index
|
"_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,
|
# In order to have a flat structure in elastic + similar behaviour to the other DocumentStores,
|
||||||
# we "unnest" all value within "meta"
|
# we "unnest" all value within "meta"
|
||||||
if "meta" in doc.keys():
|
if "meta" in _doc.keys():
|
||||||
for k, v in doc["meta"].items():
|
for k, v in _doc["meta"].items():
|
||||||
doc[k] = v
|
_doc[k] = v
|
||||||
del doc["meta"]
|
documents_to_index.append(_doc)
|
||||||
bulk(self.client, documents, request_timeout=300)
|
bulk(self.client, documents_to_index, request_timeout=300)
|
||||||
|
|
||||||
def get_document_count(self, index: Optional[str] = None,) -> int:
|
def get_document_count(self, index: Optional[str] = None,) -> int:
|
||||||
if index is None:
|
if index is None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user