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.
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:
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
}
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"]
}
}
}
fixed in 2.4 branch with https://github.com/elastic/elasticsearch/commit/6e5260d2c493a1461f9180b5004eceddce1e89c9.
Also added specific tests in master: https://github.com/elastic/elasticsearch/commit/7894eba2b3fd17bd035b91ec02c1205ef738d6e0.
Most helpful comment
you should use terms to match mutiply items.
GET /.../.../_search
{
"query": {
"terms": {
"skills": ["python", "ruby"]
}
}
}