# How do you build a org chart?

**URL:** <https://discuss.elastic.co/t/how-do-you-build-a-org-chart/60225>\
**Category:** Kibana\
**Tags:** elastic-stack-graph\
**Created:** [September 10, 2016, 9:38pm UTC](https://discuss.elastic.co/t/how-do-you-build-a-org-chart/60225 "2016-09-10T21:38:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![yeikel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yeikel/32/125434_2.png) [@yeikel](https://discuss.elastic.co/u/yeikel)\
**Post date:** [September 10, 2016, 9:38pm UTC](https://discuss.elastic.co/t/how-do-you-build-a-org-chart/60225/1 "2016-09-10T21:38:48Z")

</div>

I have the following data :

```
Parent_id | ID | Company name
null 1 Company A
1 2 Company B
2 3 Company C
3 4 Company D
3 5 Company E

```

My goal it is to create a graph that resembles the hierarchy of that data.

How can I define this relationship?

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [September 12, 2016, 10:39am UTC](https://discuss.elastic.co/t/how-do-you-build-a-org-chart/60225/2 "2016-09-12T10:39:51Z")

</div>

The Graph api currently relies on entities of the same type (in your case, companies) being found in the same field. If you plot companies from the `id` and `parentId` field then `id:CompanyB` will be represented as a different vertex from `parentId:CompanyB`. To overcome this you have to put a copy of company names into a common field e.g. `parent_and_child_ids`.

Here is your data and the mapping as an example:

```
DELETE org
PUT org
{
   "settings": {
	  "number_of_replicas": "0",
	  "number_of_shards": "1"
   },
   "mappings": {
	  "doc": {
		 "properties": {
			"id": {
			   "type": "string",
			   "index": "not_analyzed",
			   "copy_to":"parent_and_child_ids"
			},
			"parent_id": {
			   "type": "string",
			   "index": "not_analyzed",
			   "copy_to":"parent_and_child_ids"
			},
			"parent_and_child_ids": {
			   "type": "string",
			   "index": "not_analyzed"
			}
		 }
	  }
   }
}
POST org/doc
{ "id":"Company A" }
POST org/doc
{ "id":"Company B", "parent_id": "Company A"}
POST org/doc
{ "id":"Company C","parent_id": "Company B" }
POST org/doc
{"id":"Company D","parent_id": "Company C"}
POST org/doc
{"id":"Company E","parent_id": "Company C"}

```

Then if you use the Graph UI tool with "certainty" set to 1 and "significant links" turned off you would get this visualization:

 ![](https://us1.discourse-cdn.com/elastic/original/2X/b/b49466467c875c7afd79a2f849283e0d4783f0ea.jpg)

Note that there is no notion of "up" - we just know these companies are related and so A is not necessarily positioned at the top. Hierarchies are a special form of graph and one that our existing elastic Graph tools are not specialized for. You're probably better off loading data into a dedicated org-chart tool.

---

<div class="post-metadata">

**Author:** ![yeikel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yeikel/32/125434_2.png) [@yeikel](https://discuss.elastic.co/u/yeikel)\
**Post date:** [September 12, 2016, 1:33pm UTC](https://discuss.elastic.co/t/how-do-you-build-a-org-chart/60225/3 "2016-09-12T13:33:30Z")

</div>

> [@Mark\_Harwood](#):
>
> POST org/doc  
> { "id":"Company A" }  
> POST org/doc  
> { "id":"Company B", "parent\_id": "Company A"}  
> POST org/doc  
> { "id":"Company C","parent\_id": "Company B" }  
> POST org/doc  
> {"id":"Company D","parent\_id": "Company C"}  
> POST org/doc  
> {"id":"Company E","parent\_id": "Company C"}

I appreciate your help. Thank you!

---

<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 6, 2017, 1:42pm UTC](https://discuss.elastic.co/t/how-do-you-build-a-org-chart/60225/4 "2017-07-06T13:42:29Z")

</div>


