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


(Frederick Cheung) #1

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


(Frederick Cheung) #2

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

which is pretty much the opposite of 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.


(Ivan Brusic) #3

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


(Frederick Cheung) #4

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.


(Frederick Cheung) #5

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


(system) #6