minimum_should_match的默认值? [英] Default value of minimum_should_match?
问题描述
无法找到文档中的默认值 minimum_should_match
Cant find which is the default value of minimum_should_match
in the docs
是 0
或 1
,或者取决于查询是否只是应该
或过滤器
上下文?
Is it 0
or 1
, or depends if the query has just should
or filter
context?
推荐答案
minimum_should_match
的默认值取决于在查询和上下文上:
The default value of minimum_should_match
depends on the query and on the context:
-
1
:在查询上下文和应该
是孤独的(没有必须
或过滤器
) -
1
:在过滤器上下文(例如在bool
查询的过滤器
部分内;直到ES 6.7才有效) -
0
:在过滤器上下文(例如,在过滤器
部分中c $ c> bool 查询;自ES 7.0起为真,请参见以下说明) -
0
:在查询上下文,其中有必须
和应该
(或过滤器
和应该
)
1
: in query context andshould
is alone (nomust
orfilter
)1
: in filter context (e.g. inside afilter
part of abool
query; true until ES 6.7)0
: in filter context (e.g. inside afilter
part of abool
query; true since ES 7.0, see notes below)0
: in query context and there aremust
andshould
(orfilter
andshould
)
可以在 bool
查询:
Can be found in the documentation of the bool
query:
如果布尔查询位于查询上下文中并且具有must或filter
子句,则文档将与布尔匹配即使
都不应该匹配查询。在这种情况下,这些子句仅用于
影响得分。如果布尔查询是过滤器上下文或具有
既不是必须也不是过滤器,则应至少有一个查询中
必须与文档匹配才能使其与布尔查询匹配。可以通过设置minimum_should_match参数明确控制此行为。
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中过滤器上下文已删除,这意味着有效在过滤器上下文中,其默认值现在为 0
。
Update: ES 7.0 related changes
In Elasticsearch 7.0 the filter context has been removed, which means effectively that in filter context its default value now is 0
.
谢谢o 这个答案,这帮助我发现了这个问题。
Thanks to this answer which helped me to discover this.
这篇关于minimum_should_match的默认值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!