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

**URL:** https://discuss.elastic.co/t/elasticsearch-query-on-array-object-with-must-clause-is-giving-empty-results/284066
**Category:** Elasticsearch
**Created:** [September 13, 2021, 11:41am UTC](https://discuss.elastic.co/t/elasticsearch-query-on-array-object-with-must-clause-is-giving-empty-results/284066 "2021-09-13T11:41:37Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![RohanKumbhar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rohankumbhar/32/23649_2.png) [@RohanKumbhar](https://discuss.elastic.co/u/RohanKumbhar)
#### Post date: [September 13, 2021, 11:41am UTC](https://discuss.elastic.co/t/elasticsearch-query-on-array-object-with-must-clause-is-giving-empty-results/284066/1 "2021-09-13T11:41:37Z")

</div>

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:

```auto
{
  "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

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [September 13, 2021, 2:23pm UTC](https://discuss.elastic.co/t/elasticsearch-query-on-array-object-with-must-clause-is-giving-empty-results/284066/2 "2021-09-13T14:23:12Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [October 11, 2021, 2:24pm UTC](https://discuss.elastic.co/t/elasticsearch-query-on-array-object-with-must-clause-is-giving-empty-results/284066/3 "2021-10-11T14:24:01Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
