# Can ES return only the part of an array that match the query

**URL:** <https://discuss.elastic.co/t/can-es-return-only-the-part-of-an-array-that-match-the-query/10066>\
**Category:** Elasticsearch\
**Created:** [December 13, 2012, 3:32pm UTC](https://discuss.elastic.co/t/can-es-return-only-the-part-of-an-array-that-match-the-query/10066 "2012-12-13T15:32:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Margaret](https://avatars.discourse-cdn.com/v4/letter/m/a88e57/32.png) [@Margaret](https://discuss.elastic.co/u/Margaret)\
**Post date:** [December 13, 2012, 3:32pm UTC](https://discuss.elastic.co/t/can-es-return-only-the-part-of-an-array-that-match-the-query/10066/1 "2012-12-13T15:32:10Z")

</div>

I have documents containing like this:  
{  
... ...,  
"id":"abcabc",  
"nominations":[  
{  
"comment":"test",  
"events":[  
{  
"name":"aaa",  
"year":"2012"  
},{  
"name":"bbb",  
"year":"2011"  
}  
]  
},  
... ...  
]  
}

As you can see, there are two nested array, 'nominations' and 'events'.

When I search for docs that match {"term":{"events.name":"aaa"}} and {"term":{"events.year":"2012"}}, the document above will be returned.

But in practice, array 'events' may contains many elements like "{"name":"bbb","year":"2011"}" that don't match the query and also are useless to users. So my question is, can Elasticsearch return a document with array 'events' that contains element "{"name":"aaa","year":"2012"}" only? If not, is there any other possible ways to solve this problem? Or should I change the structure of the document?

Thanks a lot!

---

<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:** [July 6, 2017, 2:59am UTC](https://discuss.elastic.co/t/can-es-return-only-the-part-of-an-array-that-match-the-query/10066/2 "2017-07-06T02:59:59Z")

</div>


