【问题标题】:Difference between using multiple filters and specifying multiple filters in a single "and" clause使用多个过滤器和在单个“and”子句中指定多个过滤器之间的区别
【发布时间】:2015-10-24 07:20:54
【问题描述】:

我是 elasticsearch 新手,不知道这两个查询有什么区别。只是处理时间还是它们根本不同的查询。

1) filters : { and: [{
  "bool" : {
    "should" : {
      "term" : {
        "Code" : "1510"
      }
    }
  }
}
,
{
  "bool" : {
    "should" : {
      "term" : {
        "Id" : "Id3"
      }
    }
  }
}] }


2) filter: [{
  "bool" : {
    "must" : [{
      "term" : {
        "Code" : "1510"
      },
     "term":{
       "Id":"Id3"}]
     }
   }
 }]

【问题讨论】:

  • 看起来你打错了第一个查询你打算使用and而不是filters吗?
  • @keety 是的,这是正确的,语法可能是错误的,但我只是想了解应用 2 个不同的过滤器并将它们“和”组合在一个过滤器中是否有任何差异。谢谢

标签: elasticsearch filter


【解决方案1】:

OP 中的查询在逻辑上是等价的。

不过话虽如此,我发现 2) 直观、易读且更简单。

通常出于性能原因,bool 过滤器优于 and,尽管对于有问题的查询,我怀疑这种差异是可察觉的。

对于 and 过滤器,1) 中的查询最好写成如下:

    "filter": {
      "and": [
         {
            "term": {
               "Code": "1510"
            }
         },
         {
            "term": {
               "Id": "Id3"
            }
         }
      ]
   }

【讨论】:

    猜你喜欢
    • 2015-11-06
    • 2011-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-28
    • 2014-05-10
    • 1970-01-01
    相关资源
    最近更新 更多