# (Storing products) Storing and retrieving items with subsets of configuration

**URL:** <https://discuss.elastic.co/t/storing-products-storing-and-retrieving-items-with-subsets-of-configuration/154196>\
**Category:** Elasticsearch\
**Created:** [October 26, 2018, 12:12pm UTC](https://discuss.elastic.co/t/storing-products-storing-and-retrieving-items-with-subsets-of-configuration/154196 "2018-10-26T12:12:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrncgirc](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mrncgirc/32/45055_2.png) [@mrncgirc](https://discuss.elastic.co/u/mrncgirc)\
**Post date:** [October 26, 2018, 12:12pm UTC](https://discuss.elastic.co/t/storing-products-storing-and-retrieving-items-with-subsets-of-configuration/154196/1 "2018-10-26T12:12:52Z")

</div>

# Using Elasticsearch for storing product data

## Use case

We are using Elasticsearch to store "complex" products. Specifically I store Rims and Tire products.

## Mapping

We currently store a "group" of products per. hit. To be specific:

Product: Fallon C12 - Red  
This product has several size variants, to simplify the case I have here a simple matrix:  
 ![42](https://us1.discourse-cdn.com/elastic/original/3X/0/9/09f6c8b690d6d87934b3007a29594b8c03f77e4a.png)

So what we have done, which is incorrect - we know. We stored each type of variation seperately, so the product would in Elasticsearch have the fields:

- Size: 14,15,16
- Width: 235, 240, 245

However the issue here is, when filtering/searching for products we would have incorrect matches. If I search the following I would like to have a mapping that resultet 0 products:

- Size: 14
- Width: 245  
As I do not have this combination within my matrix. Instead with my current mapping I would get the product returned, as it fits with my mapping - but what I implemented is not what I intended.

My question is, how should we map this and how would our filter look in elasticsearch. I would expect that I would map the product with a nested object of "Variations", containing the sub SKU's. However, doing this I cannot figure out, how I would filter to get the expected results.

### Bonus question

If I added pricing and inventory to this nested object of variations, would I also be able to return the price of the cheapest matching variantion and sort by inventory \>= 4 ? (this would be very handy to us)

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [October 26, 2018, 12:22pm UTC](https://discuss.elastic.co/t/storing-products-storing-and-retrieving-items-with-subsets-of-configuration/154196/2 "2018-10-26T12:22:01Z")

</div>

you may want to take a look at the [nested datatype](https://www.elastic.co/guide/en/elasticsearch/reference/6.4/nested.html), along with specific type of queries and aggregations for this datatype.

Hope this helps!

---

<div class="post-metadata">

**Author:** ![mrncgirc](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mrncgirc/32/45055_2.png) [@mrncgirc](https://discuss.elastic.co/u/mrncgirc)\
**Post date:** [October 26, 2018, 12:58pm UTC](https://discuss.elastic.co/t/storing-products-storing-and-retrieving-items-with-subsets-of-configuration/154196/3 "2018-10-26T12:58:23Z")

</div>

Thank you Spinscale, I will look into it right away. If I have further questions to the nested query etc., could I post them in this thread?

---

<div class="post-metadata">

**Author:** ![mrncgirc](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mrncgirc/32/45055_2.png) [@mrncgirc](https://discuss.elastic.co/u/mrncgirc)\
**Post date:** [October 26, 2018, 1:36pm UTC](https://discuss.elastic.co/t/storing-products-storing-and-retrieving-items-with-subsets-of-configuration/154196/4 "2018-10-26T13:36:10Z")

</div>

Hi Spinscale,

It works great. Thank you for your quick reply.

---

<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:** [November 23, 2018, 1:36pm UTC](https://discuss.elastic.co/t/storing-products-storing-and-retrieving-items-with-subsets-of-configuration/154196/5 "2018-11-23T13:36:10Z")

</div>

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