# Retrive parent data inside child doc from index

**URL:** https://discuss.elastic.co/t/retrive-parent-data-inside-child-doc-from-index/239495
**Category:** Elasticsearch
**Created:** [July 1, 2020, 1:33pm UTC](https://discuss.elastic.co/t/retrive-parent-data-inside-child-doc-from-index/239495 "2020-07-01T13:33:04Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Sagar\_Darekar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sagar_darekar/32/71475_2.png) [@Sagar\_Darekar](https://discuss.elastic.co/u/Sagar_Darekar)
#### Post date: [July 1, 2020, 1:33pm UTC](https://discuss.elastic.co/t/retrive-parent-data-inside-child-doc-from-index/239495/1 "2020-07-01T13:33:04Z")

</div>

We have a requirement that we need to retrieve parent fields inside the child document.  
Actually we have a mapping for the index as below:

```auto
{
    "mappings": {
        "properties": {
            "relation_type": {
                "eager_global_ordinals": true,
                "type": "join",
                "relations": {
                    "user": "forum"
                }
            }
        }
    }
}

```

Parent and child relationship is maintained between user and forum. I need to retrieve the user(parents) data inside the forum(child).  
For example - User doc

```auto
{
  "hn": "handle",
  "iu": "user-image-url",
  "uId": "user-id",
  "relation_type": {
    "name": "user"
  }
}

```

And forum doc -

```auto
{
    "uId": "userId",
    "pId": "postId",
    "relation_type": {
      "name": "forum",
      "parent": "userID"
    }
}

```

I need to write a query such that it retrieves user data(user image) inside child data. For example - below is the result I wanted in the forum(child) query result with iu(image URL) from the user.

```auto
{
    "uId": "userId",
    "pId": "postId",
     "iu": "user image" //user image from user doc
    "relation_type": {
      "name": "forum",
      "parent": "userID"
    }
}

```

I have posted the same on the stack overflow forum. - [https://stackoverflow.com/questions/62468004/retrive-parent-data-embeded-in-child-doc-from-elastic-search-index](https://stackoverflow.com/questions/62468004/retrive-parent-data-embeded-in-child-doc-from-elastic-search-index)

Need to know if it is possible or not, if yes then how?

---

<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 29, 2020, 1:33pm UTC](https://discuss.elastic.co/t/retrive-parent-data-inside-child-doc-from-index/239495/2 "2020-07-29T13:33:22Z")

</div>

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