# Employee Hierarchy Usecase

**URL:** <https://discuss.elastic.co/t/employee-hierarchy-usecase/29859>\
**Category:** Elasticsearch\
**Created:** [September 23, 2015, 6:47pm UTC](https://discuss.elastic.co/t/employee-hierarchy-usecase/29859 "2015-09-23T18:47:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sgandhirajan](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@sgandhirajan](https://discuss.elastic.co/u/sgandhirajan)\
**Post date:** [September 23, 2015, 6:47pm UTC](https://discuss.elastic.co/t/employee-hierarchy-usecase/29859/1 "2015-09-23T18:47:50Z")

</div>

Whether Elastic Search supports to store the entire employee hierarchy. The lowest employee may have n number of supervisor. The manager of lowest employee may have n-1 number of supervisor.  
Oracle support parent child recursive query to get all the supervisor in the hierarchy for of an employee.  
How to arrange the data in Elastic Search? How to retrieve all the supervisors in the hierarchy for a given employee?  
I see the parent and child relations were documented in ElasticSearch but the parent and child were of different type. In Employee Hierarchy the parent and child would be of same type.  
Does Elastic Search supports this kind of usecase?

---

<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:** [September 23, 2015, 7:04pm UTC](https://discuss.elastic.co/t/employee-hierarchy-usecase/29859/2 "2015-09-23T19:04:51Z")

</div>

My first guess is to use a path tokenizer.

You have an example for another use case here: [https://www.elastic.co/guide/en/elasticsearch/guide/current/denormalization-concurrency.html](https://www.elastic.co/guide/en/elasticsearch/guide/current/denormalization-concurrency.html)

HTH

---

<div class="post-metadata">

**Author:** ![sgandhirajan](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@sgandhirajan](https://discuss.elastic.co/u/sgandhirajan)\
**Post date:** [September 30, 2015, 11:08pm UTC](https://discuss.elastic.co/t/employee-hierarchy-usecase/29859/3 "2015-09-30T23:08:01Z")

</div>

But my requirement is to find all the managers in upper hierarchy for a given employee id.  
The one you suggested gives me all the employees till the leaf node for a given manager.

---

<div class="post-metadata">

**Author:** ![sgandhirajan](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@sgandhirajan](https://discuss.elastic.co/u/sgandhirajan)\
**Post date:** [September 30, 2015, 11:21pm UTC](https://discuss.elastic.co/t/employee-hierarchy-usecase/29859/4 "2015-09-30T23:21:44Z")

</div>

Ok got your concept.

---

<div class="post-metadata">

**Author:** ![sgandhirajan](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@sgandhirajan](https://discuss.elastic.co/u/sgandhirajan)\
**Post date:** [September 30, 2015, 11:27pm UTC](https://discuss.elastic.co/t/employee-hierarchy-usecase/29859/5 "2015-09-30T23:27:15Z")

</div>

Hi dadoonet,

In that case i have to find upper hierarchy for every employee and store it in separate field and use that field as path tokenizer.  
But finding upper hierarchy for every employee is very very costly operation.

Is there any way to run a recursion query option in Elastic Search to find the list manager in upper hierarchy?

---

<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:47pm UTC](https://discuss.elastic.co/t/employee-hierarchy-usecase/29859/6 "2017-07-05T23:47:19Z")

</div>


