minimum_should_match 百分比对于查询搜索的实际作用是什么?
What does actually minimum_should_match in percentage work for query search?
我想了解 minimum_should_match 如何在 elasticsearch 中进行查询搜索
GET /customers/_search
{
"query": {
"bool": {
"must":[
{
"query_string":{
"query": "大月亮",
"default_field":"fullName",
"minimum_should_match": "70%" ------> experimented with this value
}
}
]
}
}
}
我对查询中的百分比进行了试验,发现中文得到了不同的结果?
我尝试阅读文档但没有清楚地了解此选项的工作原理?
minimum_should_match 参数适用于 "bool" 查询中的 "should" 子句。使用此参数,您可以指定文档必须匹配多少个 should 子句才能匹配查询。
考虑以下查询:
{
"query": {
"bool" : {
"must" : {
"term" : { "user" : "kimchy" }
},
"filter": {
"term" : { "tag" : "tech" }
},
"must_not" : {
"range" : {
"age" : { "gte" : 10, "lte" : 20 }
}
},
"should" : [
{ "term" : { "tag" : "wow" } },
{ "term" : { "tag" : "elasticsearch" } },
{ "term" : { "tag" : "Whosebug" } }
],
"minimum_should_match" : 2,
"boost" : 1.0
}
}
}
此处只有至少 2 个 should 子句匹配时,文档才会匹配。这意味着如果在 "tags" 字段中同时包含 "Whosebug" 和 "wow" 的文档将匹配,但在标签字段中仅包含 "elasticsearch" 的文档将不会被视为匹配。
使用百分比时,指定应匹配的 should 子句的百分比。因此,如果您有 4 个 should 子句并将 minimum_should_match 设置为 50%,那么如果其中至少 2 个 should 子句匹配,则文档将被视为匹配。
有关 minimum_should_match 的更多信息,请参见 the documentation。在那里你可以读到 "optional clauses",它是 "bool" 查询中的 "should"。
我想了解 minimum_should_match 如何在 elasticsearch 中进行查询搜索
GET /customers/_search
{
"query": {
"bool": {
"must":[
{
"query_string":{
"query": "大月亮",
"default_field":"fullName",
"minimum_should_match": "70%" ------> experimented with this value
}
}
]
}
}
}
我对查询中的百分比进行了试验,发现中文得到了不同的结果?
我尝试阅读文档但没有清楚地了解此选项的工作原理?
minimum_should_match 参数适用于 "bool" 查询中的 "should" 子句。使用此参数,您可以指定文档必须匹配多少个 should 子句才能匹配查询。
考虑以下查询:
{
"query": {
"bool" : {
"must" : {
"term" : { "user" : "kimchy" }
},
"filter": {
"term" : { "tag" : "tech" }
},
"must_not" : {
"range" : {
"age" : { "gte" : 10, "lte" : 20 }
}
},
"should" : [
{ "term" : { "tag" : "wow" } },
{ "term" : { "tag" : "elasticsearch" } },
{ "term" : { "tag" : "Whosebug" } }
],
"minimum_should_match" : 2,
"boost" : 1.0
}
}
}
此处只有至少 2 个 should 子句匹配时,文档才会匹配。这意味着如果在 "tags" 字段中同时包含 "Whosebug" 和 "wow" 的文档将匹配,但在标签字段中仅包含 "elasticsearch" 的文档将不会被视为匹配。
使用百分比时,指定应匹配的 should 子句的百分比。因此,如果您有 4 个 should 子句并将 minimum_should_match 设置为 50%,那么如果其中至少 2 个 should 子句匹配,则文档将被视为匹配。
有关 minimum_should_match 的更多信息,请参见 the documentation。在那里你可以读到 "optional clauses",它是 "bool" 查询中的 "should"。