From e22cf333edfd6e9bee78e2b5fe6b53055f27774a Mon Sep 17 00:00:00 2001 From: Lynn Date: Fri, 24 Apr 2026 21:38:19 +0800 Subject: [PATCH] Fix: allow search id or _id (#14356) ### What problem does this PR solve? Allow search id or _id when using es as doc_engine. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --- rag/utils/es_conn.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/rag/utils/es_conn.py b/rag/utils/es_conn.py index 5b04340879..3e0ab369f5 100644 --- a/rag/utils/es_conn.py +++ b/rag/utils/es_conn.py @@ -170,6 +170,16 @@ class ESConnection(ESConnectionBase): bool_query.filter.append( Q("bool", must_not=Q("range", available_int={"lt": 1}))) continue + if k == "id": + if not v: + continue + if isinstance(v, list): + bool_query.filter.append( + Q("bool", should=[Q("terms", id=v), Q("terms", _id=v)], minimum_should_match=1)) + elif isinstance(v, str) or isinstance(v, int): + bool_query.filter.append( + Q("bool", should=[Q("term", id=v), Q("term", _id=v)], minimum_should_match=1)) + continue if not v: continue if isinstance(v, list):