# Return matched nested object instead of root parent document

**URL:** <https://discuss.elastic.co/t/return-matched-nested-object-instead-of-root-parent-document/29464>\
**Category:** Elasticsearch\
**Created:** [September 17, 2015, 8:40am UTC](https://discuss.elastic.co/t/return-matched-nested-object-instead-of-root-parent-document/29464 "2015-09-17T08:40:18Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![jaikit](https://avatars.discourse-cdn.com/v4/letter/j/f475e1/32.png) [@jaikit](https://discuss.elastic.co/u/jaikit)\
**Post date:** [September 20, 2015, 11:47pm UTC](https://discuss.elastic.co/t/return-matched-nested-object-instead-of-root-parent-document/29464/3 "2015-09-20T23:47:12Z")

</div>

You need to add filter in your aggregation which will be equal to your main query. Here is the post with similar use case and solution to it.

> [@Aggregation over nested documents](https://discuss.elastic.co/t/aggregation-over-nested-documents/27810):
>
> Folks, First all great shout out to Elastic community and team for designing and building clean product. Great job! I am running a query to generate aggregations on nested documents. I have created the gist of all the curl calls (index creation, mapping and query. ) As you see in the mapping and my query, I am trying to generate aggregations on item name. In this case aggregations are generated over query results. That said I see aggregation of other nested documents as well in final result. G…

Let me know if this works for you.

---

_[View the full topic](https://discuss.elastic.co/t/return-matched-nested-object-instead-of-root-parent-document/29464)._
