Search code examples
elasticsearchelasticsearch-aggregationelasticsearch-dsl

getting query_string malformed query, expected [END_OBJECT] but found [FIELD_NAME]


I have the below query when i try to execute i am getting the exception [query_string] malformed query, expected [END_OBJECT] but found [FIELD_NAME]

{
  "query" : {
   "query_string": {
        "default_field": "shipmentId",
        "query": "\"123\""
    },
    "bool" : {
      "filter" : {
        "terms" : {
          "exceptionId" : ["1", "2"]
        }
      },
      "must_not" : {
        "terms" : {
          "id" : ["1"]
        }
      }
    }
  }
}

Solution

  • Your query is almost correct, you simply need to move the query_string query inside the bool/must section:

    {
      "query": {
        "bool": {
          "must": {
            "query_string": {
              "default_field": "shipmentId",
              "query": "\"123\""
            }
          },
          "filter": {
            "terms": {
              "exceptionId": [
                "1",
                "2"
              ]
            }
          },
          "must_not": {
            "terms": {
              "id": [
                "1"
              ]
            }
          }
        }
      }
    }