Regards kb_id at ElasticSearch insert, update, delete. (#6105)

### What problem does this PR solve?

Regards kb_id at ElasticSearch insert, update, delete. Close #6066

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
Zhichang Yu 2025-03-14 17:34:02 +08:00 committed by GitHub
parent 485bc7d7d6
commit 4fffee6695
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -284,6 +284,7 @@ class ESConnection(DocStoreConnection):
assert "_id" not in d assert "_id" not in d
assert "id" in d assert "id" in d
d_copy = copy.deepcopy(d) d_copy = copy.deepcopy(d)
d_copy["kb_id"] = knowledgebaseId
meta_id = d_copy.pop("id", "") meta_id = d_copy.pop("id", "")
operations.append( operations.append(
{"index": {"_index": indexName, "_id": meta_id}}) {"index": {"_index": indexName, "_id": meta_id}})
@ -316,6 +317,7 @@ class ESConnection(DocStoreConnection):
def update(self, condition: dict, newValue: dict, indexName: str, knowledgebaseId: str) -> bool: def update(self, condition: dict, newValue: dict, indexName: str, knowledgebaseId: str) -> bool:
doc = copy.deepcopy(newValue) doc = copy.deepcopy(newValue)
doc.pop("id", None) doc.pop("id", None)
condition["kb_id"] = knowledgebaseId
if "id" in condition and isinstance(condition["id"], str): if "id" in condition and isinstance(condition["id"], str):
# update specific single document # update specific single document
chunkId = condition["id"] chunkId = condition["id"]
@ -399,6 +401,7 @@ class ESConnection(DocStoreConnection):
def delete(self, condition: dict, indexName: str, knowledgebaseId: str) -> int: def delete(self, condition: dict, indexName: str, knowledgebaseId: str) -> int:
qry = None qry = None
assert "_id" not in condition assert "_id" not in condition
condition["kb_id"] = knowledgebaseId
if "id" in condition: if "id" in condition:
chunk_ids = condition["id"] chunk_ids = condition["id"]
if not isinstance(chunk_ids, list): if not isinstance(chunk_ids, list):