【问题标题】:Elasticsearch – combine ids query with must_not clauseElasticsearch – 将 ids 查询与 must_not 子句结合起来
【发布时间】:2014-12-23 19:25:50
【问题描述】:

我想将ids 查询与must_not 子句结合起来。我正在使用 (re)tire gem 和 rails 应用程序。

我正在做这样的事情:

query do
  ids ["foo", "bar", "test"]
end

哪个有效。但是,当我尝试将它与 must_not 子句结合使用时,我收到错误 - must_not 仅适用于 boolean 范围,不包括 ids 查询。有没有办法将这两个查询结合起来?

【问题讨论】:

    标签: ruby-on-rails ruby elasticsearch tire retire


    【解决方案1】:

    你需要使用的ES查询是这个:

    GET /some_index/some_type/_search
    {
      "query": {
        "bool": {
          "must": [
            {
              "ids": {
                "values": ["foo", "bar", "test"]
              }
            }
          ],
          "must_not": [
            {
              "match": {
                "name": "whatever"
              }
            }
          ]
        }
      }
    }
    

    因此,您需要布尔范围,must 与您的 ids 和一个 must_not 与您的不得匹配查询。

    【讨论】:

      猜你喜欢
      • 2020-07-14
      • 2020-08-03
      • 2020-09-04
      • 2018-04-06
      • 1970-01-01
      • 2022-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多