This commit is contained in:
sladro 2026-02-02 22:35:23 +08:00
parent ab3c9a769a
commit 01fa68af27

View File

@ -188,6 +188,7 @@ class KBESService:
index = KBConfig.KB_ES_INDEX index = KBConfig.KB_ES_INDEX
url = f"{KBConfig.KB_ES_URL}/{index}/_search" url = f"{KBConfig.KB_ES_URL}/{index}/_search"
# 与线上排查/运维 curl 查询保持一致,避免 DSL 差异导致“bash 命中正确、API 命中错误”。
query = { query = {
"size": KBConfig.KB_TOP_K, "size": KBConfig.KB_TOP_K,
"track_total_hits": False, "track_total_hits": False,
@ -206,29 +207,15 @@ class KBESService:
"version", "version",
], ],
"query": { "query": {
"bool": { "multi_match": {
"should": [ "query": question,
{ "fields": [
"multi_match": { "question^3",
"query": question, "answer^1.5",
"fields": [ "title^2",
"question^3", "content",
"answer^1.5",
"title^2",
"content",
"tags^1.2",
"category^1.1",
],
"type": "best_fields",
"minimum_should_match": "60%",
}
},
{"match_phrase": {"question": {"query": question, "boost": 5}}},
{"match_phrase": {"answer": {"query": question, "boost": 2}}},
{"match_phrase": {"title": {"query": question, "boost": 3}}},
{"match_phrase": {"content": {"query": question, "boost": 2}}},
], ],
"minimum_should_match": 1, "type": "best_fields",
} }
}, },
} }