# Parent/Child Modeling Question

**URL:** <https://discuss.elastic.co/t/parent-child-modeling-question/42547>\
**Category:** Elasticsearch\
**Created:** [February 24, 2016, 3:45am UTC](https://discuss.elastic.co/t/parent-child-modeling-question/42547 "2016-02-24T03:45:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Latchezar\_Kostov](https://avatars.discourse-cdn.com/v4/letter/l/f07891/32.png) [@Latchezar\_Kostov](https://discuss.elastic.co/u/Latchezar_Kostov)\
**Post date:** [February 24, 2016, 3:45am UTC](https://discuss.elastic.co/t/parent-child-modeling-question/42547/1 "2016-02-24T03:45:33Z")

</div>

Hello all,

Per the Elastic 2.2 documentation, one of the restrictions of Parent/Child is that the Parent and Child types cannot be the same.

For that reason, I am trying to figure out what the best way would be to model some data as follows:

A parent device, such as a Router, may be of some type that includes an ID, and a Name. Now, a child of that server may be something like a Network Port, which itself would have an ID and a Name. This port may have many levels of sub-ports (logical ways of separating the network port), which would again have an ID and a Name. This is the way one of our Networking Monitoring Systems models it's devices, and I would like to save that relationship tree within Elastic.

An example of something I have seen is Router ---\> Port ---\> Sub-Port ---\> Sub-Port ---\> Sub-Port. I would want each one of these to be the same type, and to have a parent/child relationship so that I can ultimately walk up the tree and get to the top-most parent.

What is a good way of Modeling this if you cannot have the same type for a Parent and a Child, especially when you want to be able to always add a child to the last parent if it in fact has one?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [February 26, 2016, 12:24am UTC](https://discuss.elastic.co/t/parent-child-modeling-question/42547/2 "2016-02-26T00:24:58Z")

</div>

> [@Latchezar\_Kostov](#):
>
> Per the Elastic 2.2 documentation, one of the restrictions of Parent/Child is that the Parent and Child types cannot be the same.

You mean this - [Parent/Child changes | Elasticsearch Guide [2.0] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/2.0/breaking_20_parent_child_changes.html)?

> The mapping for the parent type can be added at the same time as the mapping for the child type, but cannot be added before the child type.

---

<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:13pm UTC](https://discuss.elastic.co/t/parent-child-modeling-question/42547/3 "2017-07-05T23:13:29Z")

</div>


