# How to query top 1 Child document for each unique parent document?

**URL:** <https://discuss.elastic.co/t/how-to-query-top-1-child-document-for-each-unique-parent-document/74434>\
**Category:** Elasticsearch\
**Created:** [February 8, 2017, 9:37pm UTC](https://discuss.elastic.co/t/how-to-query-top-1-child-document-for-each-unique-parent-document/74434 "2017-02-08T21:37:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sathish\_Dv](https://avatars.discourse-cdn.com/v4/letter/s/e19b73/32.png) [@Sathish\_Dv](https://discuss.elastic.co/u/Sathish_Dv)\
**Post date:** [February 8, 2017, 9:37pm UTC](https://discuss.elastic.co/t/how-to-query-top-1-child-document-for-each-unique-parent-document/74434/1 "2017-02-08T21:37:29Z")

</div>

Hi,  
I am trying to query elasticsearch in such a way the return the latest child document or any one child document for each unique parent document. I am indexing UserId as Parent document and User metadata information to child document. Each UserId will have multiple metadata info indexed as Child document. So I need to query to return top 1 child document for each UserId in Parent document. Can anyone help me on how to achieve this in Elasticsearch. I am using ES 5.1.

Thanks.

---

<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:** [March 8, 2017, 9:38pm UTC](https://discuss.elastic.co/t/how-to-query-top-1-child-document-for-each-unique-parent-document/74434/2 "2017-03-08T21:38:02Z")

</div>

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