gpt4 book ai didi

elasticsearch - minimum_should_match 的默认值?

转载 作者:行者123 更新时间:2023-11-29 02:45:04 25 4
gpt4 key购买 nike

无法在文档中找到 minimum_should_match 的默认值

https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-minimum-should-match.html

0 还是 1,或者取决于查询是否只有 shouldfilter 上下文?

最佳答案

minimum_should_match 的默认值取决于查询和上下文:

  • 1:在query context并且 should 是单独的(没有 mustfilter)
  • 1:在filter context (例如,在 bool 查询的 filter 部分内;在 ES 6.7 之前为真)
  • 0:在 filter context 中(例如,在 bool 查询的 filter 部分内;自 ES 7.0 起为真,请参阅下面的注释)
  • 0:在 query context 中并且有 mustshould(或 filtershould)

可以在 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/

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