简体   繁体   中英

Elasticsearch 2.x - new bool query

After upgrading to Elasticsearch 2.x I got an issue with the following query:

{   "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.

Thanks in advance.

You can simply remove the filtered/filter part and modify your query like this:

{
  "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
                }
              }
            ]
          }
        }
      ]
    }
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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