Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix: improve document filtering in full text search(elasticsearch) (#22683)

uply23333ab012fe1a2fa
diff --git a/api/core/rag/datasource/vdb/elasticsearch/elasticsearch_vector.py b/api/core/rag/datasource/vdb/elasticsearch/elasticsearch_vector.py
index 44cc5d3e98c..ad397171839 100644
--- a/api/core/rag/datasource/vdb/elasticsearch/elasticsearch_vector.py
+++ b/api/core/rag/datasource/vdb/elasticsearch/elasticsearch_vector.py
@@ -147,10 +147,17 @@ class ElasticSearchVector(BaseVector):
return docs
def search_by_full_text(self, query: str, **kwargs: Any) -> list[Document]:
- query_str = {"match": {Field.CONTENT_KEY.value: query}}
+ query_str: dict[str, Any] = {"match": {Field.CONTENT_KEY.value: query}}
document_ids_filter = kwargs.get("document_ids_filter")
+
if document_ids_filter:
- query_str["filter"] = {"terms": {"metadata.document_id": document_ids_filter}} # type: ignore
+ query_str = {
+ "bool": {
+ "must": {"match": {Field.CONTENT_KEY.value: query}},
+ "filter": {"terms": {"metadata.document_id": document_ids_filter}},
+ }
+ }
+
results = self._client.search(index=self._collection_name, query=query_str, size=kwargs.get("top_k", 4))
docs = []
for hit in results["hits"]["hits"]: