mirror of
https://github.com/deepset-ai/haystack.git
synced 2025-11-13 16:43:44 +00:00
Add method to update meta fields for documents in Elasticsearch (#242)
This commit is contained in:
parent
a6ec430931
commit
5210c8c2ab
@ -143,6 +143,10 @@ class ElasticsearchDocumentStore(BaseDocumentStore):
|
|||||||
documents_to_index.append(_doc)
|
documents_to_index.append(_doc)
|
||||||
bulk(self.client, documents_to_index, request_timeout=300)
|
bulk(self.client, documents_to_index, request_timeout=300)
|
||||||
|
|
||||||
|
def update_document_meta(self, id: str, meta: Dict[str, str]):
|
||||||
|
body = {"doc": meta}
|
||||||
|
self.client.update(index=self.index, doc_type="_doc", id=id, body=body)
|
||||||
|
|
||||||
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:
|
||||||
index = self.index
|
index = self.index
|
||||||
|
|||||||
@ -1,3 +1,6 @@
|
|||||||
|
import pytest
|
||||||
|
import time
|
||||||
|
|
||||||
from haystack.database.base import Document
|
from haystack.database.base import Document
|
||||||
|
|
||||||
|
|
||||||
@ -10,3 +13,12 @@ def test_get_all_documents(document_store_with_docs):
|
|||||||
doc = document_store_with_docs.get_document_by_id(documents[0].id)
|
doc = document_store_with_docs.get_document_by_id(documents[0].id)
|
||||||
assert doc.id == documents[0].id
|
assert doc.id == documents[0].id
|
||||||
assert doc.text == documents[0].text
|
assert doc.text == documents[0].text
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("document_store_with_docs", [("elasticsearch")], indirect=True)
|
||||||
|
def test_elasticsearch_update_meta(document_store_with_docs):
|
||||||
|
document = document_store_with_docs.query(query=None, filters={"name": ["filename1"]})[0]
|
||||||
|
document_store_with_docs.update_document_meta(document.id, meta={"meta_field": "updated_meta"})
|
||||||
|
time.sleep(1)
|
||||||
|
updated_document = document_store_with_docs.query(query=None, filters={"name": ["filename1"]})[0]
|
||||||
|
assert updated_document.meta["meta_field"] == "updated_meta"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user