# How to store ecommerce set/nonset products in elasticsearch?

**URL:** <https://discuss.elastic.co/t/how-to-store-ecommerce-set-nonset-products-in-elasticsearch/52279>\
**Category:** Elasticsearch\
**Created:** [June 9, 2016, 6:00am UTC](https://discuss.elastic.co/t/how-to-store-ecommerce-set-nonset-products-in-elasticsearch/52279 "2016-06-09T06:00:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bharat2016](https://avatars.discourse-cdn.com/v4/letter/b/bbce88/32.png) [@bharat2016](https://discuss.elastic.co/u/bharat2016)\
**Post date:** [June 9, 2016, 6:00am UTC](https://discuss.elastic.co/t/how-to-store-ecommerce-set-nonset-products-in-elasticsearch/52279/1 "2016-06-09T06:00:05Z")

</div>

Hi,

How to store ecommerce set/nonset products in elasticsearch with aggregation,sort,search.

currently I am using parent-child relationship with it, but for aggregation and sort it need to store merged values in the parent.that is not working well with proper aggregation [count.So](http://count.So) it doesn't satisfy my requirement.

Current schema is as follow,

Parent .  
{  
\_id: "s113",  
name: "sample product set",  
"mrps" :[  
100,  
200  
]  
}

Children  
{  
\_id:"c100",  
parent: "s113",  
name: "sample product set",  
"mrp":100  
},  
{  
\_id:"c101",  
parent: "s113",  
name: "sample product set",  
"mrp" : 100  
},  
{  
\_id:"c102",  
parent: "s113",  
name: "sample product set",  
"mrp" :200  
},  
{  
\_id:"c103",  
parent: "s113",  
name: "sample product set",  
"mrp": 200  
}

I am performing aggregation,sort and search on parent and filtering done at child to fetch single client.

---

<div class="post-metadata">

**Author:** ![mikemccand](https://avatars.discourse-cdn.com/v4/letter/m/f04885/32.png) [@mikemccand](https://discuss.elastic.co/u/mikemccand)\
**Post date:** [June 9, 2016, 1:08pm UTC](https://discuss.elastic.co/t/how-to-store-ecommerce-set-nonset-products-in-elasticsearch/52279/2 "2016-06-09T13:08:26Z")

</div>

Are you sure the aggregation counts are wrong if you don't pull `"mrps"` up to the parent?

Have you explored nested documents instead?

Mike McCandless

---

<div class="post-metadata">

**Author:** ![bharat2016](https://avatars.discourse-cdn.com/v4/letter/b/bbce88/32.png) [@bharat2016](https://discuss.elastic.co/u/bharat2016)\
**Post date:** [June 10, 2016, 4:53am UTC](https://discuss.elastic.co/t/how-to-store-ecommerce-set-nonset-products-in-elasticsearch/52279/3 "2016-06-10T04:53:01Z")

</div>

Yes I had used nested documents but it also gives wrong result.

Parent child become wrong in following scenario.  
Parent .  
{  
\_id: "s113",  
name: "sample product set",  
"mrps" :[  
100,  
200  
]  
}

Children  
{  
\_id:"c100",  
parent: "s113",  
name: "sample product set",  
"mrp":100  
},  
{  
\_id:"c101",  
parent: "s113",  
name: "sample product set",  
"mrp" : 100  
},  
{  
\_id:"c102",  
parent: "s113",  
name: "sample product set",  
"mrp" :200  
},  
{  
\_id:"c103",  
parent: "s113",  
name: "sample product set",  
"mrp": 200  
}

I had used children aggregation.result comes like this.

Price:  
100 - 2 counts  
200 - 2 counts

But my expected output is like:

100 - 1 count  
200 - 1 count

---

<div class="post-metadata">

**Author:** ![bharat2016](https://avatars.discourse-cdn.com/v4/letter/b/bbce88/32.png) [@bharat2016](https://discuss.elastic.co/u/bharat2016)\
**Post date:** [June 14, 2016, 9:48am UTC](https://discuss.elastic.co/t/how-to-store-ecommerce-set-nonset-products-in-elasticsearch/52279/4 "2016-06-14T09:48:47Z")

</div>

Please provide me an solution as early as possible.

---

<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, 10:43pm UTC](https://discuss.elastic.co/t/how-to-store-ecommerce-set-nonset-products-in-elasticsearch/52279/5 "2017-07-05T22:43:59Z")

</div>


