Elasticsearch Query on Array object with must clause is giving empty results

Hi There,

I'm always getting empty results when i query the array objects with multi must clause as mentioned below

Index docs:

POST test/doc/1
{
"name":["Alex","Bob","Matt"],
"company":"ABC",
"city":"NY"
}

POST test/doc/2
{
"name":["Alex","Bob","John"],
"company":"XYZ",
"city":"OZ"
}

Query

POST test/_search
{
"query": {
"bool": {
"must": [
{
"term": {
"name": {
"value": "Alex"
}
}
},
{
"match_phrase_prefix": {
"company": "ABC"
}
}
]
}
}
}

RESULT:

{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 0,
    "max_score" : null,
    "hits" : [ ]
  }
}

Expected result: It should return 1 hit

The query works as expected. You are using a term query, which requires you to specify the search terms as stored in the inverted index. However it is stored as alex in the inverted index due to analysis. Try using a match instead of a term query.