# Aggregation of top inner documents?

**URL:** <https://discuss.elastic.co/t/aggregation-of-top-inner-documents/80799>\
**Category:** Elasticsearch\
**Created:** [March 31, 2017, 11:30am UTC](https://discuss.elastic.co/t/aggregation-of-top-inner-documents/80799 "2017-03-31T11:30:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Petr\_Novotny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/petr_novotny/32/16438_2.png) [@Petr\_Novotny](https://discuss.elastic.co/u/Petr_Novotny)\
**Post date:** [March 31, 2017, 11:30am UTC](https://discuss.elastic.co/t/aggregation-of-top-inner-documents/80799/1 "2017-03-31T11:30:38Z")

</div>

Hi everbody,

I have a document with nested objects (product and its categories). What I need is to search by a category and know which inner document (category) best matched the search. It is simple with inner\_hits.

{  
"query": {  
"nested": {  
"path": "categoryPath",  
"query": {  
"match": {  
"categoryPath.path": {  
"query": "children hoodie"  
}  
}  
},  
"inner\_hits": {  
"size": 1  
}  
}  
}

Then I need to get unique names of categories matched. Is it possible to collect it using any aggregation? - to collect unique values of all "best" matched inner hits? thank you:)

---

<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:** [April 28, 2017, 11:30am UTC](https://discuss.elastic.co/t/aggregation-of-top-inner-documents/80799/2 "2017-04-28T11:30:39Z")

</div>

Closed on April 28, 2017, 11:30am UTC

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