# 2.1.1 won't parse query involving not/and filters that parses in 1.7.x

**URL:** https://discuss.elastic.co/t/2-1-1-wont-parse-query-involving-not-and-filters-that-parses-in-1-7-x/37880
**Category:** Elasticsearch
**Created:** [December 23, 2015, 6:11pm UTC](https://discuss.elastic.co/t/2-1-1-wont-parse-query-involving-not-and-filters-that-parses-in-1-7-x/37880 "2015-12-23T18:11:20Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Frederick\_Cheung](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/frederick_cheung/32/1874_2.png) [@Frederick\_Cheung](https://discuss.elastic.co/u/Frederick_Cheung)
#### Post date: [December 23, 2015, 6:11pm UTC](https://discuss.elastic.co/t/2-1-1-wont-parse-query-involving-not-and-filters-that-parses-in-1-7-x/37880/1 "2015-12-23T18:11:20Z")

</div>

Hi,

The following query works fine in 1.7.x:

```
curl -XPOST localhost:9200/dummy/document -d '{
  "ids": [1,2,3]
}'
curl -XPOST localhost:9200/dummy/document/_search -d '
{
  "query": {
    "filtered":{
      "query": {"match_all": {}},
      "filter": {
        "not": {
          "and": [
            {
              "terms": {
                "ids": [6]
              }
            }
          ]
        }
      }
    }
  }
}'

```

However in ES 2.0.1 and 2.1.1 I get

{"error":{"root\_cause":[{"type":"query\_parsing\_exception","reason":"[\_na] query malformed, must start with start\_object","index":"dummy","line":11,"col":26}],"type":"search\_phase\_execution\_exception","reason":"all shards failed","phase":"query","grouped":true,"failed\_shards":[{"shard":0,"index":"dummy","node":"q\_wr-wtpSOOgH0NJ9HVI-Q","reason":{"type":"query\_parsing\_exception","reason":"[\_na] query malformed, must start with start\_object","index":"dummy","line":11,"col":26}}]}

Using the long form of the and or the not filter seems to be ok: these 2 queries parse ok.

```
{
  "query": {
    "filtered":{
      "query": {"match_all": {}},
      "filter": {
        "not": {
          "filter":{
            "and": [
              {
                "terms": {
                  "ids": [6]
                }
              }  
            ]
          }
        }
      }
    }
  },
  "_source": false
}

```

or

```
{
  "query": {
    "filtered":{
      "query": {"match_all": {}},
      "filter": {
        "not": {
          "and": {
            "filters":[
              {
                "terms": {
                  "ids": [6]
                }
              }
            ]
          }
        }
      }
    }
  },
  "_source": false
}

```

I couldn't find mention of this in the 2.0 breaking changes document - should the first query still work?

Thanks,

Fred

---

<div class="post-metadata">

### Author: ![Frederick\_Cheung](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/frederick_cheung/32/1874_2.png) [@Frederick\_Cheung](https://discuss.elastic.co/u/Frederick_Cheung)
#### Post date: [December 23, 2015, 6:19pm UTC](https://discuss.elastic.co/t/2-1-1-wont-parse-query-involving-not-and-filters-that-parses-in-1-7-x/37880/2 "2015-12-23T18:19:21Z")

</div>

It does look like this was deliberate: [https://github.com/elastic/elasticsearch/pull/12890](https://github.com/elastic/elasticsearch/pull/12890)

which is pretty much the opposite of [https://github.com/elastic/elasticsearch/issues/1987](https://github.com/elastic/elasticsearch/issues/1987) , so I don't understand the assertion that this is impossible to support.

At the very least something in the breaking changes document would be nice.

---

<div class="post-metadata">

### Author: ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)
#### Post date: [December 24, 2015, 5:23pm UTC](https://discuss.elastic.co/t/2-1-1-wont-parse-query-involving-not-and-filters-that-parses-in-1-7-x/37880/3 "2015-12-24T17:23:19Z")

</div>

I do not know the specific cause, but have you tried using the new query  
syntax? Filtered queries are deprecated, but still should work. Better to  
write a test case in the new format in case there was some fix.

Ivan

---

<div class="post-metadata">

### Author: ![Frederick\_Cheung](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/frederick_cheung/32/1874_2.png) [@Frederick\_Cheung](https://discuss.elastic.co/u/Frederick_Cheung)
#### Post date: [December 24, 2015, 6:17pm UTC](https://discuss.elastic.co/t/2-1-1-wont-parse-query-involving-not-and-filters-that-parses-in-1-7-x/37880/4 "2015-12-24T18:17:57Z")

</div>

I tried with

```
curl -XPOST localhost:9200/dummy/document/_search -d '
{
  "query": {
    "bool":{
      "must": {"match_all": {}},
      "filter": {
        "not": {
          "and": [
            {
              "terms": {
                "ids": [6]
              }
            }
          ]
        }
      }
    }
  }
}'

```

and got the same result. Ideally I'd like code that runs against 1.7.x and 2.x, update to 2.x and then start removing the deprecated stuff.

---

<div class="post-metadata">

### Author: ![Frederick\_Cheung](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/frederick_cheung/32/1874_2.png) [@Frederick\_Cheung](https://discuss.elastic.co/u/Frederick_Cheung)
#### Post date: [January 5, 2016, 8:39am UTC](https://discuss.elastic.co/t/2-1-1-wont-parse-query-involving-not-and-filters-that-parses-in-1-7-x/37880/5 "2016-01-05T08:39:45Z")

</div>

Any opinions on whether this syntax should be allowed in 2.0 / 2.1 ?

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [July 5, 2017, 11:27pm UTC](https://discuss.elastic.co/t/2-1-1-wont-parse-query-involving-not-and-filters-that-parses-in-1-7-x/37880/6 "2017-07-05T23:27:04Z")

</div>


