malformed query, expected END_OBJECT but found FIELD_NAME error in Kibana (Elastic Search)

Zabs picture Zabs · Jun 1, 2017 · Viewed 34.6k times · Source

I am running the following GET query within my Kibana Console and for some reason I am getting a error in the response window as follows :

// error

[match] malformed query, expected [END_OBJECT] but found [FIELD_NAME]

Can anyone suggest why I am not able to use multiple match blocks within the 'should' section?

// response - if i take out one of the match blocks it works??

{
  "error": {
   "root_cause": [
     {
       "type": "parsing_exception",
       "reason": "[match] malformed query, expected [END_OBJECT] but found [FIELD_NAME]",
        "line": 9,
        "col": 13
     }
   ],
    "type": "parsing_exception",
    "reason": "[match] malformed query, expected [END_OBJECT] but found [FIELD_NAME]",
    "line": 9,
    "col": 13
   },
   "status": 400
}

// my query

GET _search
  {
    "query": {
      "bool": {
        "should": [
        {
           "match": {
           "text": "facebook advice"
        },
           "match": {
           "profile": "facebook advice"
        }
      }
    ],
    "minimum_number_should_match": 1,
    "filter": {
      "term": {
        "accountid": "22"
      }
    }
  }
}

Answer

Val picture Val · Jun 1, 2017

Your query is malformed. Write it like this instead:

GET _search
{
  "query": {
    "bool": {
      "should": [
        {
          "match": {
            "text": "facebook advice"
          }
        },
        {
          "match": {
            "profile": "facebook advice"
          }
        }
      ],
      "minimum_number_should_match": 1,
      "filter": {
        "term": {
          "accountid": "22"
        }
      }
    }
  }
}