elasticsearch中minimum_should_match的一些理解

elasticsearch query中的minimum_should_match ,字面意思就很清晰了,就是最小匹配度,但是它却有很多种配置方式。
正向匹配度比如 "minimum_should_match":3 官方原文解释是:Indicates a fixed value regardless of the number of optional clauses.
这里要说明一下为什么是optional clauses(翻译为可选的子句),因为对于被analyzer分解出来的每一个term都会构造成一个should的bool query的查询,每个term变成一个term query子句。
例如"query": "how not to be",被解析成:
{
  "bool": {
    "should": [
      { "term": { "body": "how"}},
      { "term": { "body": "not"}},
      { "term": { "body": "to"}},
      { "term": { "body": "be"}}
    ],
    "minimum_should_match": 3
  }
}
(注:在bool query中minimum_should_match只能紧跟在should的后面,放其他地方会出异常)




或者 "minimum_should_match":75%,可以配置一个一个百分比,至少optional clauses至少满足75%,这里是向下取整的。
比如有5个clause,5*75%=3.75,向下取整为3,也就是至少需要match 3个clause。


逆向匹配和正向匹配相反,比如我们可以近似理解为-25%和75%表示的是一个意思,但是有些小小的差异,比如有5个clause,逆向匹配-25%,5*25%=1.25,取整是1,5-1=4,即要匹配4个clause,而75%算出来是3个clause。




组合匹配(Combination)"minimum_should_match": 3<90%,官方的解释有点搞,感觉描述的有点复杂。描述如下:
A positive integer, followed by the less-than symbol, followed by any of the previously mentioned specifiers is a conditional specification. It indicates that if the number of optional clauses is equal to (or less than) the integer, they are all required, but if it’s greater than the integer, the specification applies. In this example: if there are 1 to 3 clauses they are all required, but for 4 or more clauses only 90% are required.
意思是说如果1<clauses<=3,那么两个条件都要满足( they are all required),如果clauses>3,那么只要满足90%这个条件。说的真是绕。。。
  • 11
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值