gpt4 book ai didi

elasticsearch - 将查询与必须匹配和应该匹配用于多重匹配查询

转载 作者:行者123 更新时间:2023-12-03 01:00:52 25 4
gpt4 key购买 nike

我正在尝试使用多匹配查询,如下所示。对于某些字段,我希望在该字段中找到所有关键字,但对于某些其他字段,至少应找到1个关键字。据此,我认为可以使用must和should组合两个多重匹配查询。

 "from": 0,
"size": 10,
"explain": true,
"query": {
"bool": {
"must": [
{
"multi_match": {
"type": "best_fields",
"query": "hp 301",
"fields": [
"MPN^9",
"SKU^8"
]
}
}
],
"should": [
{"multi_match": {
"type": "best_fields",
"query": "hp 301",
"fields": [
"Name.raw2^7.5",
"Name^7",
"Description^6"
]
}}
]
}
}

如果我正确理解MPN和SKU仅在字段中找到hp和301时才必须匹配,但是当我分析得分时,会在下面看到此信息。

产品具有:“MPN”:“CF 301 A”

的解释:
 "_explanation": {
"value": 2.0636692,
"description": "sum of:",
"details": [
{
"value": 1.0522164,
"description": "max of:",
"details": [
{
"value": 1.0522164,
"description": "product of:",
"details": [
{
"value": 2.1044328,
"description": "sum of:",
"details": [
{
"value": 2.1044328,
"description": "weight(MPN:301 in 375) [PerFieldSimilarity], result of:",
"details": [
{
"value": 2.1044328,
"description": "score(doc=375,freq=1.0), product of:",
"details": [
{
"value": 0.45506343,
"description": "queryWeight, product of:",
"details": [
{
"value": 9,
"description": "boost",
"details": []
},
{
"value": 9.248965,
"description": "idf(docFreq=2, maxDocs=11471)",
"details": []
},
{
"value": 0.0054668393,
"description": "queryNorm",
"details": []
}
]
},

如果MPN字段中只有301,为什么MPN返回分数?现场是否也不需要“hp”?如果没有,我该如何使其完全匹配?

最佳答案

使用多重匹配查询时,搜索字词默认会解析为单独的单词,如果这些单词中的任何一个匹配,整个查询都会匹配。要打破此默认行为,您需要做的是添加“and”运算符,这样它才知道只有找到两个术语才匹配。

"from": 0,
"size": 10,
"explain": true,
"query": {
"bool": {
"must": [
{
"multi_match": {
"type": "best_fields",
"query": "hp 301",
"fields": [
"MPN^9",
"SKU^8"
],
"operator": "and"
}
}
],
"should": [
{"multi_match": {
"type": "best_fields",
"query": "hp 301",
"fields": [
"Name.raw2^7.5",
"Name^7",
"Description^6"
]
}}
]
}
}

希望有帮助!

关于elasticsearch - 将查询与必须匹配和应该匹配用于多重匹配查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37723663/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com