# How to fetch hierarchical data using elastic search

**URL:** <https://discuss.elastic.co/t/how-to-fetch-hierarchical-data-using-elastic-search/128631>\
**Category:** Elasticsearch\
**Created:** [April 19, 2018, 5:55am UTC](https://discuss.elastic.co/t/how-to-fetch-hierarchical-data-using-elastic-search/128631 "2018-04-19T05:55:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![preetidashore](https://avatars.discourse-cdn.com/v4/letter/p/5f9b8f/32.png) [@preetidashore](https://discuss.elastic.co/u/preetidashore)\
**Post date:** [April 19, 2018, 5:55am UTC](https://discuss.elastic.co/t/how-to-fetch-hierarchical-data-using-elastic-search/128631/1 "2018-04-19T05:55:33Z")

</div>

I want to fetch hierarchical data using elastic search  
I have tried **'has\_parent' ,'has\_child' and 'term- aggregation'** but it is returning hierarchy only up to **1** level. But I want to get complete hierarchy for specific offer.

I have an index of type ‘ **offers** ’.

Let’s say it contains below documents as described below:

Each offer is being referred by another offer and that offer is again being referred by an another offer. So on.  
Ex: **Offer\_A is being referred by offer\_B , Offer\_B is being referred by Offer\_C and Offer\_D** this may go to any level

```
{
     “id”: “offer_A”,
      “dependsOnOffer” :[
                   “offer_X”     
         ]
}

{
     “id”: “offer_B”,
      “dependsOnOffer” :[
                   “offer_A”  
         ]
}

{
     “id”: “offer _C”,
      “dependsOnOffer” :[
                   “offer_B”     
         ]
}

	 
{
     “id”: “offer_D”,
      “dependsOnOffer” :[
                   “offer_B”     
         ]
}

```

**Desired Output :**  
When I am looking for offer\_A and want to fetch all of its **depending on offers**  
Then It should return  
**Offer\_B , Offer\_C , Offer\_D**

**Please guide us how can we achieve this requirement to be fulfilled. Thanks in Advance !!!**

---

<div class="post-metadata">

**Author:** ![preetidashore](https://avatars.discourse-cdn.com/v4/letter/p/5f9b8f/32.png) [@preetidashore](https://discuss.elastic.co/u/preetidashore)\
**Post date:** [April 22, 2018, 4:31pm UTC](https://discuss.elastic.co/t/how-to-fetch-hierarchical-data-using-elastic-search/128631/2 "2018-04-22T16:31:31Z")

</div>

Is there any update on this issue ?  
Please help to resolve it

---

<div class="post-metadata">

**Author:** ![Akib\_Ali](https://avatars.discourse-cdn.com/v4/letter/a/b5a626/32.png) [@Akib\_Ali](https://discuss.elastic.co/u/Akib_Ali)\
**Post date:** [April 24, 2018, 8:35am UTC](https://discuss.elastic.co/t/how-to-fetch-hierarchical-data-using-elastic-search/128631/3 "2018-04-24T08:35:33Z")

</div>

> [@preetidashore](#):
>
> lease guide us how can we achieve this requirement to be fulfilled. Thanks in Advance !!!

@dadoonet Could you pleas help here.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 24, 2018, 8:54am UTC](https://discuss.elastic.co/t/how-to-fetch-hierarchical-data-using-elastic-search/128631/4 "2018-04-24T08:54:49Z")

</div>

No I don't think I can.

I'd suggest to provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

---

<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:** [May 22, 2018, 8:54am UTC](https://discuss.elastic.co/t/how-to-fetch-hierarchical-data-using-elastic-search/128631/5 "2018-05-22T08:54:50Z")

</div>

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