# Deep nesting and recommendation for its usage

**URL:** <https://discuss.elastic.co/t/deep-nesting-and-recommendation-for-its-usage/185321>\
**Category:** Elasticsearch\
**Created:** [June 12, 2019, 4:14am UTC](https://discuss.elastic.co/t/deep-nesting-and-recommendation-for-its-usage/185321 "2019-06-12T04:14:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![abhigyan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abhigyan/32/47917_2.png) [@abhigyan](https://discuss.elastic.co/u/abhigyan)\
**Post date:** [June 12, 2019, 4:14am UTC](https://discuss.elastic.co/t/deep-nesting-and-recommendation-for-its-usage/185321/1 "2019-06-12T04:14:15Z")

</div>

Hello ES community!

We are building cloud application which is going to have high scaling data store inside an RDBMS. What we are trying to do is moving the relational data which are searchable to the ES which everyone faces I've seen on the internet already. Now, it turned out that we had to use nested objects (documents) and it went around 4 levels deep almost per document.

The ES docs say that we have to use the nesting in special case only. We also cannot find some good references for querying the nested data properly. As we are up to using `elasticsearch-dsl` for python, could not seem to find a trace of searching nested data there too. Is it that there is less community support in this high level python client? How is the future of it, should we use it in production ?

So my concern is that is it good idea to use nesting in ES or not ?  
If not, can we use RDBMS to get relations and build up query objects and send to ES to only search documents (RDBMS + ES together) ?

If curious about how our data looks like, it is similar to this document structure:

```auto
{
    car_doc {
        car_name,
        car_suppliers [
             {
                  supplier_name,
                  supplier_services [
                        {
                               service_type,
                               service_offerings [{ ... }]
                        }
                  ]
             }
        ],
    }
}

```

Thanks!

---

<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:** [June 12, 2019, 5:58am UTC](https://discuss.elastic.co/t/deep-nesting-and-recommendation-for-its-usage/185321/2 "2019-06-12T05:58:57Z")

</div>

Elasticsearch is a document store, which requires you to change how you model your data when you move from a relational database. Trying to mimic a relational structure using parent-child or nested document is generally not the way to approach this as they are not a replacement for the lack of joins. Instead think about what entities you want to search for and denormalize your data into documents that match this. This will result in a flat model that is generally a lot easier to query.

This means data will be duplicated and if you make changes at the higher levels of the hierarchy you will need to update multiple documents. This is however often a reasonable tradeoff as doing a bit more work at index or update time in exchange for faster and simpler queries generally is worth it if updates are infrequent.

---

<div class="post-metadata">

**Author:** ![abhigyan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abhigyan/32/47917_2.png) [@abhigyan](https://discuss.elastic.co/u/abhigyan)\
**Post date:** [June 12, 2019, 6:46am UTC](https://discuss.elastic.co/t/deep-nesting-and-recommendation-for-its-usage/185321/3 "2019-06-12T06:46:04Z")

</div>

Okay, sounds right, thanks! So we are now on the way to de-normalize and flatten our stuff. For duplication part, wouldn't the index only store reference to the textual data in the documents? which I think will reduce duplication.

In our documents, it will happen that we will require to query related data fields which are multiple in numbers from multiple documents; we cannot duplicate them, which may tend us to querying multiple documents. Any suggestions for querying multiple documents at the same time efficiently? I mean would it be better to query two times or perform joins inside ES (putting it all in the query).

Thanks for the support!

---

<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:** [June 12, 2019, 7:14am UTC](https://discuss.elastic.co/t/deep-nesting-and-recommendation-for-its-usage/185321/4 "2019-06-12T07:14:39Z")

</div>

I can’t tell as I do not know your data. Making recommendations based on simplified sample data can often lead to important aspects being missed or overlooked.

---

<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 10, 2019, 7:14am UTC](https://discuss.elastic.co/t/deep-nesting-and-recommendation-for-its-usage/185321/5 "2019-07-10T07:14:40Z")

</div>

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