michael Salam
michael Salam

Reputation: 343

elasticsearch how to include many values for the same field in the match phrase

This is my query

GET blablabla/_search
{
  "query": {
    "bool": {
      "must": [
        {"match" : {"source" : "balblabla"}},
        {"match" :{"blablablab" : "JBR"}},
        {"match": {"city" : "blab bla"}},
        {"match" : {"something": ["Balcony" , "Gym"]}}
      ]
    }
  }
}

I am getting this error:

{
   "error": {
      "root_cause": [
         {
            "type": "query_parsing_exception",
            "reason": "[match] query parsed in simplified form, with direct field name, but included more options than just the field name, possibly use its 'options' form, with 'query' element?",
            "index": "index name goes here",
            "line": 8,
            "col": 35
         }
      ],
      "type": "search_phase_execution_exception",
      "reason": "all shards failed",
      "phase": "query",
      "grouped": true,
      "failed_shards": [
         {
            "shard": 0,
            "index": "index name goes here",
            "node": "4Qjq5UGPSZO2Qtg-ECI_mQ",
            "reason": {
               "type": "query_parsing_exception",
               "reason": "[match] query parsed in simplified form, with direct field name, but included more options than just the field name, possibly use its 'options' form, with 'query' element?",
               "index": "index name goes here",
               "line": 8,
               "col": 35
            }
         }
      ]
   },
   "status": 400
}

When I remove this line

{"match" : {"something": ["Balcony" , "Gym"]}}

It works fine, but why does that line causes a parsing error, since arrays are fine in json?

My elasticsearch version is 2.2

Upvotes: 2

Views: 1601

Answers (1)

Daniel Andres Acevedo
Daniel Andres Acevedo

Reputation: 568

The error comes from the parser, you must specified with an "OR" when passing multiple needles.

to fix your case you must replace

    {
  "match": {
    "something": [
      "Balcony",
      "Gym"
    ]
  }
}

WITH

{
  "match": {
    "something": "Balcony OR Gym"
  }
}

so at the end it should look like this:

{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "source": "balblabla"
          }
        },
        {
          "match": {
            "blablablab": "JBR"
          }
        },
        {
          "match": {
            "city": "blab bla"
          }
        },
        {
          "match": {
            "something": "Balcony OR Gym"
          }
        }
      ]
    }
  }
}

hope this will help you and point you in the right path :)

regards, Daniel

Upvotes: 4

Related Questions