Search code examples
elasticsearchquerydsl

Nested Query Compatibility in Elastic Search 5.6


I have below payload in my REST call (POST) and its working fine Elastic search 2.1.1 but not in ES 5.6.7

{"from":0,"size":5,"sort":[{"releasedDate":{"order":"desc"}}],"query":{"query_string":{"query":{"query":"demo demo*","defaultOperator":"and"}}}}

In ES 5.6.7, I got below exception

{
"error": {
    "root_cause": [
        {
            "type": "parsing_exception",
            "reason": "[query_string] unknown token [START_OBJECT] after [query]",
            "line": 1,
            "col": 96
        }
    ],
    "type": "parsing_exception",
    "reason": "[query_string] unknown token [START_OBJECT] after [query]",
    "line": 1,
    "col": 96
},
"status": 400

}

Anyone have any idea why the payload is not working in ES 5.6.7 ??


Solution

  • In ES 5.6.7 you need to write it like this:

    {
      "from": 0,
      "size": 5,
      "sort": [
        {
          "releasedDate": {
            "order": "desc"
          }
        }
      ],
      "query": {
        "query_string": {
          "query": "demo demo*",
          "default_operator": "and"
        }
      }
    }
    

    Find the documentation here.