gpt4 book ai didi

elasticsearch - 如何结合多个匹配查询?

转载 作者:行者123 更新时间:2023-12-03 00:13:19 24 4
gpt4 key购买 nike

我的目的是结合以下两个多重匹配查询。我希望MPN或SKU字段必须与每个关键字匹配。因此,关键字“hp”和“301”都必须存在于MPN或SKU中。
或Name或Name.raw应该具有关键字之一“hp”或“301”。
与MPN / SKU完全匹配的得分应更高。
我写了如下查询,但是尽管有文档具有这些条件,但它不返回任何结果。
我的问题是

1) Does must query require keyword to be found in both SKU and MPN
for the multi_match query?

2) Combination of must and should is AND or OR? it looks like AND
for me as it doesn't return any result. if it is AND, how to make it
as OR? I cant find any operator on bool. I tried to wrap in another
should query but it didnt help.

对于我的目的,我也感谢任何查询建议。
   "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"
]
}}
]
}
}

最佳答案

我假设这个问题与这里的这个问题有关。 How do && and || work constructing queries in NEST?

如果我正确理解的话,必须和应该的结合会像下面所说的那样起到应有的促进作用


bool
> must
> term1
> should
> term2
> term3
> term4

这是因为 bool(boolean) 查询一旦具有must子句,就应该开始作为促进因素。所以在

previous you could get back results that ONLY contain term1 this is clearly not what you want in the strict boolean sense of the input.



因此,我将查询更改为2个应查询的查询,其中一个查询具有“AND”运算符。因此,这将像MUST一样,将强制所有搜索关键字都应在字段中找到。
"from": 0,
"size": 10,
"explain": true,
"query": {
"bool": {
"should": [
{
"multi_match": {
"type": "best_fields",
"query": "hp 301",
"fields": [
"MPN^9",
"SKU^8"
],
"operator": "and"
}
} ,
{
"multi_match": {
"type": "best_fields",
"query": "hp 301",
"fields": [
"Name.raw2^7.5",
"Name^7"
]
}
}
]

}
}

关于elasticsearch - 如何结合多个匹配查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38894540/

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