百分比中的 minimum_should_match 实际上对查询搜索有什么作用?

Sor*_*iuc 2 elasticsearch kibana elk

我想了解更多minimum_should_match中是如何工作的elasticsearch为AA查询搜索

GET /customers/_search
{
  "query": {
     "bool": {
        "must":[
           {
           "query_string":{
              "query": "???",
              "default_field":"fullName",
              "minimum_should_match": "70%" ------> experimented with this value
           }
        }
      ]
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

我试验了查询中的百分比,我可以看到我得到了不同的中文结果?

我尝试阅读文档,但没有清楚地了解此选项是如何工作的?

Daa*_*tie 6

minimum_should_match 参数适用于“bool”查询中的“should”子句。使用此参数可以指定文档必须匹配多少个 should 子句才能匹配查询。

考虑以下查询:

{
  "query": {
    "bool" : {
      "must" : {
        "term" : { "user" : "kimchy" }
      },
      "filter": {
        "term" : { "tag" : "tech" }
      },
      "must_not" : {
        "range" : {
          "age" : { "gte" : 10, "lte" : 20 }
        }
      },
      "should" : [
        { "term" : { "tag" : "wow" } },
        { "term" : { "tag" : "elasticsearch" } },
        { "term" : { "tag" : "stackoverflow" } }
      ],
      "minimum_should_match" : 2,
      "boost" : 1.0
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

Here a document will only be a match if minimum 2 should clauses match. This means if a document with both "stackoverflow" and "wow" in the "tags" field will match, but a document with only "elasticsearch" in the tags field will not be considered a match.

When using percentages, you specify the percentage of should clauses that should match. So if you have 4 should clauses and you set the minimum_should_match at 50%, then a document will be considered a match if at least 2 of those should clauses match.

More about minimum_should_match can be found in the documentation. There you can read it's for "optional clauses", which is "should" in a "bool" query.

  • “query_string”中的“minimum_should_match”选项在此页面上有更详细的解释:https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#查询字符串最小应匹配 (2认同)