Rahul
Rahul

Reputation: 101

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

Upvotes: 1

Views: 2350

Answers (1)

Val
Val

Reputation: 217314

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

Upvotes: 2

Related Questions