Update Elastics store delete() (#84)
This commit is contained in:
parent
9a96a9b876
commit
3ac277cc0b
|
@ -153,7 +153,12 @@ class ElasticsearchDocumentStore(BaseDocumentStore):
|
||||||
|
|
||||||
def delete(self, ids: Union[List[str], str]):
|
def delete(self, ids: Union[List[str], str]):
|
||||||
"""Delete document by id"""
|
"""Delete document by id"""
|
||||||
raise NotImplementedError("Delete by-id is a Work-in-Progress.")
|
if not isinstance(ids, list):
|
||||||
|
ids = [ids]
|
||||||
|
|
||||||
|
query = {"query": {"terms": {"_id": ids}}}
|
||||||
|
self.client.delete_by_query(index=self.index_name, body=query)
|
||||||
|
self.client.indices.refresh(index=self.index_name)
|
||||||
|
|
||||||
def save(self, path: Union[str, Path]):
|
def save(self, path: Union[str, Path]):
|
||||||
"""Save document to path"""
|
"""Save document to path"""
|
||||||
|
|
|
@ -176,6 +176,34 @@ _elastic_search_responses = [
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
# delete
|
||||||
|
(
|
||||||
|
meta_success,
|
||||||
|
{
|
||||||
|
"took": 10,
|
||||||
|
"timed_out": False,
|
||||||
|
"total": 1,
|
||||||
|
"deleted": 1,
|
||||||
|
"batches": 1,
|
||||||
|
"version_conflicts": 0,
|
||||||
|
"noops": 0,
|
||||||
|
"retries": {"bulk": 0, "search": 0},
|
||||||
|
"throttled_millis": 0,
|
||||||
|
"requests_per_second": -1.0,
|
||||||
|
"throttled_until_millis": 0,
|
||||||
|
"failures": [],
|
||||||
|
},
|
||||||
|
),
|
||||||
|
# check exists
|
||||||
|
(
|
||||||
|
meta_success,
|
||||||
|
{"_shards": {"total": 2, "successful": 1, "failed": 0}},
|
||||||
|
),
|
||||||
|
# count
|
||||||
|
(
|
||||||
|
meta_success,
|
||||||
|
[{"epoch": "1700549363", "timestamp": "06:49:23", "count": "2"}],
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -260,4 +288,8 @@ def test_elastic_document_store(elastic_api):
|
||||||
docs = store.query("text")
|
docs = store.query("text")
|
||||||
assert len(docs) == 3, "Document store query() failed"
|
assert len(docs) == 3, "Document store query() failed"
|
||||||
|
|
||||||
|
# delete test
|
||||||
|
store.delete(first_doc.doc_id)
|
||||||
|
assert store.count() == 2, "Document store delete() failed"
|
||||||
|
|
||||||
elastic_api.assert_called()
|
elastic_api.assert_called()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user