# About elasticsearch returned innerhits for a query

**URL:** https://discuss.elastic.co/t/about-elasticsearch-returned-innerhits-for-a-query/199636
**Category:** Elasticsearch
**Created:** [September 16, 2019, 10:51am UTC](https://discuss.elastic.co/t/about-elasticsearch-returned-innerhits-for-a-query/199636 "2019-09-16T10:51:02Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![jyothsna](https://avatars.discourse-cdn.com/v4/letter/j/aca169/32.png) [@jyothsna](https://discuss.elastic.co/u/jyothsna)
#### Post date: [September 16, 2019, 10:51am UTC](https://discuss.elastic.co/t/about-elasticsearch-returned-innerhits-for-a-query/199636/1 "2019-09-16T10:51:02Z")

</div>

I have a query which has 2 nested fields.After applying this query for an index documents the 2 fields are matched for a document and ES returned that document along with innerhits. But the innerhits contains only one field.But i want all the matched field objects.

my query looks like this  
{  
"query": {  
"bool": {  
"must": [  
{  
"constant\_score": {  
"filter": {  
"nested": {  
"inner\_hits": {  
"\_source": true  
},  
"path": "penDocuments",  
"query": {  
"bool": {  
"must": [  
{  
"match": {  
"penDocuments.type": "Passport"  
}  
},  
{  
"match": {  
"penDocuments.values": "zzzzz"  
}  
}  
]  
}  
}  
}  
},  
"boost": 100  
}  
},  
{  
"constant\_score": {  
"filter": {  
"nested": {  
"inner\_hits": {  
"\_source": true  
},  
"path": "penDocuments",  
"query": {  
"bool": {  
"must": [  
{  
"match": {  
"penDocuments.type": "PAN"  
}  
},  
{  
"match": {  
"penDocuments.values": "735fHgBT1"  
}  
}  
]  
}  
}  
}  
},  
"boost": 100  
}  
}  
]  
}  
}  
}

and my response innerhits is

"inner\_hits": {  
"penDocuments": {  
"hits": {  
"total": 1,  
"max\_score": 1.3862944,  
"hits": [  
{  
"\_index": "neglistindividual\_junit",  
"\_type": "details",  
"\_id": "869",  
"\_nested": {  
"field": "penDocuments",  
"offset": 0  
},  
"\_score": 1.3862944,  
"\_source": {  
"type": "PAN",  
"values": [  
"735fHgBT1",  
"Zwgt3ES21"  
]  
}  
}  
]  
}  
}  
}

but i expected both pan and passport fields in the innerhits. How can i obtain that?

---

<div class="post-metadata">

### Author: ![jyothsna](https://avatars.discourse-cdn.com/v4/letter/j/aca169/32.png) [@jyothsna](https://discuss.elastic.co/u/jyothsna)
#### Post date: [September 20, 2019, 10:47am UTC](https://discuss.elastic.co/t/about-elasticsearch-returned-innerhits-for-a-query/199636/2 "2019-09-20T10:47:18Z")

</div>

we can set individual names for inner hits  
for example:  
for first query  
inner\_hits:{  
"name" : hit1  
}  
and for second query  
inner\_hits:{  
"name": hit2  
}

like this you can get all the innerhits without overwriting.

---

<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 18, 2019, 10:47am UTC](https://discuss.elastic.co/t/about-elasticsearch-returned-innerhits-for-a-query/199636/3 "2019-10-18T10:47:19Z")

</div>

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