Elasticsearch: "match" with "query" parameter accepts list input and gives wrong results

Created on 4 Jan 2016  路  4Comments  路  Source: elastic/elasticsearch

There is an inconsistency in match query in simple form and with query parameter. The latter gives an erroneous result with a list input whereas the former refuses the list input with parse error.

GET /.../.../_search
{
    "query": {
        "match": {
            "skills": ["python", "ruby"]
        }
    }
}

results an parse error, as expected.

GET /.../.../_search
{
    "query": {
        "match": {
            "skills": {
                "query": ["python", "ruby"]
            }
        }
    }
}

gives the same output as with "query": ["xxx","yyy", "ruby"] or "query": ["ruby"], considering ONLY the last item of the list and ignoring the rest.

:SearcSearch >bug good first issue

Most helpful comment

you should use terms to match mutiply items.
GET /.../.../_search
{
"query": {
"terms": {
"skills": ["python", "ruby"]
}
}
}

All 4 comments

This is broke in 2.2, but may already be fixed in master?

I can confirm the above incorrect behavior on both 2.1.1 and 2.2.

On current master (4c1e93bd89c), both forms raise errors, albeit slightly differently:

Shorthand form

curl -X POST 'http://localhost:9200/company/employee/_search?pretty=true' -d '
{
    "query": {
        "match": {
            "skills": ["python", "ruby"]
        }
    }
}'
{
  "error" : {
    "root_cause" : [ {
      "type" : "illegal_state_exception",
      "reason" : "Can't get text on a START_ARRAY at 5:13"
    } ],
    "type" : "illegal_state_exception",
    "reason" : "Can't get text on a START_ARRAY at 5:13"
  },
  "status" : 500
}

With "query" param

curl -X POST 'http://localhost:9200/company/employee/_search?pretty=true' -d '
{
    "query": {
        "match": {
            "skills": {
                "query": ["python", "ruby"]
            }
        }
    }
}'
{
  "error" : {
    "root_cause" : [ {
      "type" : "parsing_exception",
      "reason" : "[match] unknown token [START_ARRAY] after [query]",
      "line" : 6,
      "col" : 17
    } ],
    "type" : "parsing_exception",
    "reason" : "[match] unknown token [START_ARRAY] after [query]",
    "line" : 6,
    "col" : 17
  },
  "status" : 400
}

you should use terms to match mutiply items.
GET /.../.../_search
{
"query": {
"terms": {
"skills": ["python", "ruby"]
}
}
}

Was this page helpful?
0 / 5 - 0 ratings