# Searching with subdocuments (children or nested or smth else)?

**URL:** https://discuss.elastic.co/t/searching-with-subdocuments-children-or-nested-or-smth-else/42119
**Category:** Elasticsearch
**Created:** [February 18, 2016, 9:55am UTC](https://discuss.elastic.co/t/searching-with-subdocuments-children-or-nested-or-smth-else/42119 "2016-02-18T09:55:01Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![ddorian43](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ddorian43/32/36093_2.png) [@ddorian43](https://discuss.elastic.co/u/ddorian43)
#### Post date: [February 18, 2016, 9:55am UTC](https://discuss.elastic.co/t/searching-with-subdocuments-children-or-nested-or-smth-else/42119/1 "2016-02-18T09:55:01Z")

</div>

Hi !,

I have an ecommerce-search I'm building. My problem, is that some products have ALOT of subproducts. Let me explain. The products are clothes. On the clothes I have "Levy jeans Blue" "Levy jeans white" "Levy jeans green", "Levy jeans black", "Levy jeans red" . By my count, only 5% of the products have different variants.

What I want, is that when you search "Levy jeans" only 1 product shows from the whole collection of "Levy jeans" (doesn't matter which color in this case), while if I were to search "blue jeans" I only want the blue one to show from the whole "Levy jeans" collection.

Makes sense ? What would be the best way to implement this?  
Should I just store every variant as a separate document and group the products by "master\_product\_id" when searching ? If yes, will this also work with grouping by also another field (I will need sometimes to also group by retailer at the same time).  
Or should I use nested ? I don't think I need parent-child ?

Meaning, I want to search the whole library, and then for products that have multiple configurations, I want the highest scored product in that group. Only 5% of the products have multiple variants.

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: [July 5, 2017, 11:15pm UTC](https://discuss.elastic.co/t/searching-with-subdocuments-children-or-nested-or-smth-else/42119/2 "2017-07-05T23:15:20Z")

</div>


