
默认值
minimum_should_match取决于查询和上下文:
1
:在查询上下文中且should
单独存在(否must
或filter
)1
:在过滤器上下文中(例如filter
,在bool
查询的一部分内部;在ES 6.7之前为true)0
:在过滤器上下文中(例如filter
,在bool
查询的一部分内部;自ES 7.0起为true,请参见下面的注释)0
:在查询上下文中,有must
andshould
(或filter
andshould
)
可以在
bool查询文档中找到:
一些例子如果布尔查询位于查询上下文中,并且具有must或filter子句,则文档将与布尔查询匹配,即使没有应当匹配的查询。在这种情况下,这些子句仅用于影响得分。如果布尔查询是一个过滤器上下文,或者既没有必须查询也没有过滤器,则应该查询中的至少一个必须与文档匹配才能使其与布尔查询匹配。可以通过设置minimum_should_match参数来明确控制此行为。
查询上下文,并且
should是单独的:
POST _search{ "query": { "bool" : { "should" : [ { "term" : { "tag" : "wow" } }, { "term" : { "tag" : "elasticsearch" } } ] # default: # "minimum_should_match" : 1 } }}查询上下文,
must并与
should:
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。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)