最小值应匹配筛选查询

时间:2015-09-28 13:42:22

标签: elasticsearch

是否可以进行这样的查询

  "query": {
  "filtered": {
     "filter": {
        "terms": {
           "names": [
             "Anna",
             "Mark",
             "Joe"
           ],
           "execution" : "and"
        }
      }
    }
  } 

使用"minimum_should_match": "2"声明?

我知道我可以使用简单的查询(我已经尝试过,它有效)但我不需要计算得分。我的目标只是过滤包含2个值的文档。

分数通常会严重影响检索文档所需的时间吗?

使用此查询:

  "query": {
  "filtered": {
     "filter": {
        "terms": {
           "names": [
             "Anna",
             "Mark",
             "Joe"
           ],
           "execution" : "and",
           "minimum_should_match": "2"
        }
      }
    }
  } 

我收到了这个错误:

QueryParsingException[[my_db] [terms] filter does not support [minimum_should_match]]

1 个答案:

答案 0 :(得分:7)

最小匹配不是terms filter的参数。如果这是您正在寻找的功能,我可能会像这样重写您的查询,以使用bool query中包含的query filter

{
   "filter": {
      "query": {
         "bool": {
            "must": [
               {
                  "term": {
                     "names": "Anna"
                  }
               },
               {
                  "term": {
                     "names": "Mark"
                  }
               },
               {
                  "term": {
                     "name": "Joe"
                  }
               }
            ],
            "minimum_number_should_match": 2
         }
      }
   }
}

您将获得最接近所有三个匹配的文档,但查询也会将文档与三个术语中的两个完全匹配。 must是隐式的。我们也没有计算分数,因为我们已将查询作为过滤器执行。

相关问题