# What is the best approach on hierarchical/nested data?

**URL:** <https://discuss.elastic.co/t/what-is-the-best-approach-on-hierarchical-nested-data/26732>\
**Category:** Elasticsearch\
**Created:** [August 3, 2015, 4:06pm UTC](https://discuss.elastic.co/t/what-is-the-best-approach-on-hierarchical-nested-data/26732 "2015-08-03T16:06:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mattkim](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mattkim/32/4000_2.png) [@mattkim](https://discuss.elastic.co/u/mattkim)\
**Post date:** [August 3, 2015, 4:06pm UTC](https://discuss.elastic.co/t/what-is-the-best-approach-on-hierarchical-nested-data/26732/1 "2015-08-03T16:06:28Z")

</div>

If I have an index of products and there are nested categories such as:

Men \> Tops \> Shirts

Should I store "Mens", "Mens\>Tops", "Mens\>Tops\>Shirts" as separate categories and store them as an array:

product\_categories : ["Mens", "Mens\>Tops", "Mens\>Tops\>Shirts"] (or mapped ids)

Or should I store it as a nested data..something like:

product\_category : {  
level1: "Mens",  
level2: "Tops",  
level3: "Shirts"  
}

Or is there another approach that is best?

---

<div class="post-metadata">

**Author:** ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)\
**Post date:** [August 3, 2015, 4:33pm UTC](https://discuss.elastic.co/t/what-is-the-best-approach-on-hierarchical-nested-data/26732/2 "2015-08-03T16:33:18Z")

</div>

You might be interested in the following section of the Elasticsearch:The Definitive Guide book for this: [https://www.elastic.co/guide/en/elasticsearch/guide/current/synonyms-expand-or-contract.html#synonyms-genres](https://www.elastic.co/guide/en/elasticsearch/guide/current/synonyms-expand-or-contract.html#synonyms-genres)

---

<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:57pm UTC](https://discuss.elastic.co/t/what-is-the-best-approach-on-hierarchical-nested-data/26732/3 "2017-07-05T23:57:40Z")

</div>


