elasticsearch - 带有多个和/或流的Elasticsearch Bool查询

标签 elasticsearch

我正在尝试使用Elasticsearch查询DSL编写下面提到的SQL查询,但是我无法获得与SQL查询相同的结果。任何人都可以通过以下查询的bool查询来帮助e。我正在使用elasticsearch 2.1.1版本。

id.eq(someId)
  .and(
     (anotherId.eq(another).and(node.eq(node)))
     .or
     (domain.in(List))
    )

这就是我尝试过的。如果这是正确的,我如何在Java DSL中编写相同的查询?
{
  "query": {
    "filtered": {
      "filter": {
        "bool": {
          "must": [
            {
              "term": {
                "id": 1
              }
            }
          ]
        }
      },
      "query": {
      "bool": {
         "should": [
            {
               "bool": {
                  "must": [
                     {
                        "term": {
                           "anotherId": "ss"
                        }
                     },
                     {
                        "term": {
                           "node": "ss"
                        }
                     }
                  ]
               }
            },
            {
               "bool": {
                  "must": [
                     {
                        "terms": {
                           "domain" : [ "cc", "cc" ]
                        }
                     }
                  ]
               }
            }
         ]
      }
   }
    }
  }
}

最佳答案

这是在ES 2.1.1中执行此操作的正确方法

{
  "query": {
    "bool": {
      "filter": [
        {
          "term": {
            "id": 1
          }
        },
        {
          "bool": {
            "should": [
              {
                "bool": {
                  "filter": [
                    {
                      "term": {
                        "anotherId": "ss"
                      }
                    },
                    {
                      "term": {
                        "node": "ss"
                      }
                    }
                  ]
                }
              },
              {
                "terms": {
                  "domain": [
                    "cc",
                    "cc"
                  ]
                }
              }
            ]
          }
        }
      ]
    }
  }
}

关于elasticsearch - 带有多个和/或流的Elasticsearch Bool查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37060158/

相关文章:

elasticsearch - Elasticsearch与Cassandra集成

elasticsearch - Elasticsearch DSL过滤器,用于聚合和扩展统计信息

postgresql - 如何安装 zombodb elasticsearch 插件?

lucene - Elasticsearch - 如果词频更高,则得分更高

elasticsearch - 将多类型索引迁移到单类型索引

elasticsearch - 使用NEST V5.4重新索引-ElasticSearch

elasticsearch - 如何调整日期字段上的日期范围聚合值?

frameworks - 带有 Play 2 配置的 ElasticSearch

mongodb - MongoLab和Elasticsearch

elasticsearch - 在Elasticsearch中保留错误消息