# Return 3 nested documents per category

**URL:** https://discuss.elastic.co/t/return-3-nested-documents-per-category/28660
**Category:** Elasticsearch
**Created:** [September 4, 2015, 8:26am UTC](https://discuss.elastic.co/t/return-3-nested-documents-per-category/28660 "2015-09-04T08:26:26Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Robert\_Simon](https://avatars.discourse-cdn.com/v4/letter/r/e480ec/32.png) [@Robert\_Simon](https://discuss.elastic.co/u/Robert_Simon)
#### Post date: [September 4, 2015, 8:26am UTC](https://discuss.elastic.co/t/return-3-nested-documents-per-category/28660/1 "2015-09-04T08:26:26Z")

</div>

Hello,

We have this document structure in mongo

```
masterProduct_id: String
category: String
variants: [
  variantGroup_id: String
  priority: Number
  accessories: [
    masterProduct_id: String
    variantGroup_id: String
  ]
]

```

I need to query accessories for 1 product variant to be shown on page.  
Relations between accessories are on variants level, so identified by masterProduct\_id and variantGroup\_id pair.  
Result should be represented by array of categories and in every category top 3 variants based on "priority".

Currently we are syncing it to ES using transporter, so no nested indexes created by default.  
I am trying to reach my goal step by step and studying documentation atm.

---

<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 5, 2017, 11:52pm UTC](https://discuss.elastic.co/t/return-3-nested-documents-per-category/28660/2 "2017-07-05T23:52:05Z")

</div>


