简体   繁体   English

Elasticsearch 2.x-新的布尔查询

[英]Elasticsearch 2.x - new bool query

After upgrading to Elasticsearch 2.x I got an issue with the following query: 升级到Elasticsearch 2.x后,以下查询出现问题:

{   "query": {
    "filtered": {
      "filter": {
        "bool": {
          "should": [
            {
              "bool": {
                "must": [
                  {
                    "terms": {
                      "_type": [
                        "xxx",
                        "yyy"
                      ]
                    }
                  },
                  {
                    "exists": {
                      "field": "aaa"
                    }
                  },
                  {
                    "exists": {
                      "field": "bbb"
                    }
                  },
                  {
                    "exists": {
                      "field": "ccc"
                    }
                  }
                ]
              }
            },
            {
              "bool": {
                "must": [
                  {
                    "term": {
                      "_type": "eee"
                    }
                  },
                  {
                    "term": {
                      "f": 0
                    }
                  }
                ]
              }
            }
          ]
        }
      }
    }   } }

Basically, I do not know how to replace the 'must' inside the 'should' filter with the new query DSL rules in Elasticsearch 2.x. 基本上,我不知道如何用Elasticsearch 2.x中的新查询DSL规则替换“应该”过滤器中的“必须”。

Thanks in advance. 提前致谢。

You can simply remove the filtered/filter part and modify your query like this: 您可以简单地删除已filtered/filter部分并按如下方式修改查询:

{
  "query": {
    "bool": {
      "should": [
        {
          "bool": {
            "must": [
              {
                "terms": {
                  "_type": [
                    "xxx",
                    "yyy"
                  ]
                }
              },
              {
                "exists": {
                  "field": "aaa"
                }
              },
              {
                "exists": {
                  "field": "bbb"
                }
              },
              {
                "exists": {
                  "field": "ccc"
                }
              }
            ]
          }
        },
        {
          "bool": {
            "must": [
              {
                "term": {
                  "_type": "eee"
                }
              },
              {
                "term": {
                  "f": 0
                }
              }
            ]
          }
        }
      ]
    }
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM