无法在文档中找到 minimum_should_match
的默认值
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-minimum-should-match.html
是 0
还是 1
,或者取决于查询是否只有 should
或 filter
上下文?
最佳答案
minimum_should_match
的默认值取决于查询和上下文:
1
:在query context并且should
是单独的(没有must
或filter
)1
:在filter context (例如,在bool
查询的filter
部分内;在 ES 6.7 之前为真)0
:在 filter context 中(例如,在bool
查询的filter
部分内;自 ES 7.0 起为真,请参阅下面的注释)0
:在 query context 中并且有must
和should
(或filter
和should
)
可以在 bool
的文档中找到查询:
If the bool query is in a query context and has a must or filter clause then a document will match the bool query even if none of the should queries match. In this case these clauses are only used to influence the score. If the bool query is a filter context or has neither must or filter then at least one of the should queries must match a document for it to match the bool query. This behavior may be explicitly controlled by settings the minimum_should_match parameter.
几个例子
查询上下文和应该
是单独的:
POST _search
{
"query": {
"bool" : {
"should" : [
{ "term" : { "tag" : "wow" } },
{ "term" : { "tag" : "elasticsearch" } }
]
# default:
# "minimum_should_match" : 1
}
}
}
查询上下文和必须
连同应该
:
POST _search
{
"query": {
"bool" : {
"must" : {
"term" : { "user" : "kimchy" }
},
"should" : [
{ "term" : { "tag" : "wow" } },
{ "term" : { "tag" : "elasticsearch" } }
]
# default:
# "minimum_should_match" : 0
}
}
}
过滤上下文:
POST _search
{
"query": {
"bool": {
"filter": {
"bool": {
"must": {
"term" : { "user" : "kimchy" }
},
"should": [
{ "term" : { "tag" : "wow" } },
{ "term" : { "tag" : "elasticsearch" } }
]
# default (until ES 6.7):
# "minimum_should_match" : 1
}
}
}
}
}
更新:ES 7.0 相关变化
在 Elasticsearch 7.0 中 the filter context has been removed ,这实际上意味着在过滤器上下文中,它的默认值现在是 0
。
感谢this answer这帮助我发现了这一点。
关于elasticsearch - minimum_should_match 的默认值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48984706/