# Get child, of child, of child etc

**URL:** https://discuss.elastic.co/t/get-child-of-child-of-child-etc/102113
**Category:** Elasticsearch
**Created:** [September 28, 2017, 12:24pm UTC](https://discuss.elastic.co/t/get-child-of-child-of-child-etc/102113 "2017-09-28T12:24:08Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![emillykkejensen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/emillykkejensen/32/33984_2.png) [@emillykkejensen](https://discuss.elastic.co/u/emillykkejensen)
#### Post date: [September 28, 2017, 12:24pm UTC](https://discuss.elastic.co/t/get-child-of-child-of-child-etc/102113/1 "2017-09-28T12:24:08Z")

</div>

Postet this question on stackoverflow as well, but hoping to get better answers here.

I am trying to get all children and all parents of a doc id, where one child can be the parent, grandparent, grand grandparent etc. of multiple docs.

So let's say I have a structur like this (borrowed from [https://www.elastic.co/guide/en/elasticsearch/reference/5.6/parent-join.html](https://www.elastic.co/guide/en/elasticsearch/reference/5.6/parent-join.html)):

```
   (parent)
   question
    / \
   / \
comment answer
(child) (child)

```

In code:

```
PUT my_index
{
  "settings": {
    "mapping.single_type": true
  },
  "mappings": {
    "doc": {
      "properties": {
        "my_join_field": {
          "type": "join",
          "relations": {
            "question": ["answer", "comment"]
          }
        }
      }
    }
  }
}

```

However, one can answer comments and comment answers theoretically forever. So say I have a question, that is structured like this:

```
                               (id: 1)
                               question
                              / \
                             / \
                        answer answer
                       (id: 5) (id: 8)
                       / \ |
                      / \ |
                   comment answer answer
                  (id: 15) (id: 12) (id: 9)
                  / \ | / \  
                 / \ | / \ 
              answer answer comment answer answer 
             (id: 16)(id: 17) (id: 19) (id: 10)(id: 11)

```

How do I get all the documents (ids 1, 5, 8, 9, 10, 11, 12, 15, 16, 17, 19), only knowing id 9?

---

<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: [October 26, 2017, 12:24pm UTC](https://discuss.elastic.co/t/get-child-of-child-of-child-etc/102113/2 "2017-10-26T12:24:53Z")

</div>

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