# Mapping dilemma

**URL:** <https://discuss.elastic.co/t/mapping-dilemma/104588>\
**Category:** Elasticsearch\
**Created:** [October 19, 2017, 4:09pm UTC](https://discuss.elastic.co/t/mapping-dilemma/104588 "2017-10-19T16:09:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SebScoFr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sebscofr/32/31623_2.png) [@SebScoFr](https://discuss.elastic.co/u/SebScoFr)\
**Post date:** [October 19, 2017, 4:09pm UTC](https://discuss.elastic.co/t/mapping-dilemma/104588/1 "2017-10-19T16:09:29Z")

</div>

I need to come up with a proper data model for the following scenario:

We are building an application on which users can search for categories, stores and products.

1 Store can have multiple Products, 1 Product belongs to only 1 Store  
1 Category can have multiple Products, 1 Product can belong to multiple Categories

Originally I wanted to implement Parent/Child relationships as such:  
"store": "product"  
"category": "product"  
I realize now that this is obviously not possible since a Product can not have more than one parent.

I am thinking now of keeping that Parent/child relation between Stores and Products, and handle categorization with nested Category objects within the Product objects.  
I'm wondering if this would be the ideal approach to this? I must also say that Products will be updated on a daily basis or even more frequently, and categories will be added or removed from products regularly as well, if that has any effect on which approach I should take for this problem?

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [October 19, 2017, 4:25pm UTC](https://discuss.elastic.co/t/mapping-dilemma/104588/2 "2017-10-19T16:25:47Z")

</div>

Have you considered flattening it completely? As store seems to be updated infrequently or not at all, this could be denormalised onto the product records, and the product would then also simply have a list of categories.

Would this match how you want to query and aggregate over your data?

---

<div class="post-metadata">

**Author:** ![SebScoFr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sebscofr/32/31623_2.png) [@SebScoFr](https://discuss.elastic.co/u/SebScoFr)\
**Post date:** [October 19, 2017, 6:16pm UTC](https://discuss.elastic.co/t/mapping-dilemma/104588/3 "2017-10-19T18:16:29Z")

</div>

Hi Christian and thank you for your interest in this.

This is also a solution that I consider since stores are indeed very rarely updated.  
With this approach of nesting everything within the Product documents, is it going to be easy to query for:

- All available stores, or a specific store
- All available categories, or a specific category
- A product count for each store/category

Many 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:** [November 16, 2017, 6:16pm UTC](https://discuss.elastic.co/t/mapping-dilemma/104588/4 "2017-11-16T18:16:32Z")

</div>

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