elasticsearch - Elasticsearch 中的嵌套 bool 查询

标签 elasticsearch

我正在尝试在 Elasticsearch 中进行查询,该查询将执行以下操作: 我希望它检查具有(metropolitan_area of​​ 16 AND starts_at of 05072013)或(metropolitan_id of 16 AND starts_at "blank")的结果。

这是我当前的查询,但我觉得它需要以某种方式嵌套,但我不确定该怎么做。

{
  "query" : { 
    "bool" : {
      "must" : [
        {
          "term" : {"user" : "a"}
        }, 
        { 
          "term" :{"metropolitan_area" : "16"}
        }
      ], 
      "must_not" : [], 
      "should" :   []
    }
  }, 
  "filter" : {
    "or" : {
      "filters" : [
        {
          "term" : {"user":"519"}
        }, 
        {
          "term" : {"user":"6"}
        }, 
        {
          "term" : {"user":"5"}
        }, 
        {
          "term" : {"user":"36"}
        }, 
        {
          "term" : {"starts_at":"05072013"}
        }, 
        {
          "term" : {"starts_at":"blank"}
        }
      ]
    }
  }
}

最佳答案

正确嵌套的 bool 表达式如下所示:

{
  "filter": {
    "or" : [{
       "and" : [
          { "term" : { "metropolian_area" : 16 } },
          { "term" : { "starts_at" : 0123213 } }
       ]
    }, {
       "and" : [
          { "term" : ... },
          { "term" : ... }
       ]
    }]
  }
}

关于elasticsearch - Elasticsearch 中的嵌套 bool 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16243496/

相关文章:

elasticsearch - 两个以上节点的elasticsearch集群-镜像?

postgresql - Logstash中的两个输出。一个仅用于某些聚合

node.js - 如何忽略 Elasticsearch 中的撇号?

elasticsearch - 如何搜索包含子字符串的文档

java - 使 ElasticSearch 在配置错误时失败

elasticsearch - 基于索引名称的Elasticsearch索引生命周期管理

elasticsearch - Filebeat/Logstash 从输出中删除不需要的字段和值

json - 在文件Elasticsearch 1.7中获取索引的所有文档

elasticsearch - 如何在ElasticSearch中使用_index字段包装带有过滤器的嵌套查询?

elasticsearch - Elasticsearch Java API:用于文档计数的聚合过滤器