# Get both parent and child document

**URL:** <https://discuss.elastic.co/t/get-both-parent-and-child-document/82862>\
**Category:** Elasticsearch\
**Created:** [April 19, 2017, 10:17am UTC](https://discuss.elastic.co/t/get-both-parent-and-child-document/82862 "2017-04-19T10:17:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ToujouAya](https://avatars.discourse-cdn.com/v4/letter/t/9fc29f/32.png) [@ToujouAya](https://discuss.elastic.co/u/ToujouAya)\
**Post date:** [April 19, 2017, 10:17am UTC](https://discuss.elastic.co/t/get-both-parent-and-child-document/82862/1 "2017-04-19T10:17:28Z")

</div>

Is it possible to return both parent data and child with an Elasticsearch query?  
Example :

`PUT my_index/posts/_search { { "query": { "has_child": {"type": "comments"}}}}`

It will return only posts data. How can I get the comments data too?

---

<div class="post-metadata">

**Author:** ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)\
**Post date:** [April 21, 2017, 7:16am UTC](https://discuss.elastic.co/t/get-both-parent-and-child-document/82862/2 "2017-04-21T07:16:09Z")

</div>

You can use inner hits for this:

```auto
{
   "query" : {
       "has_child" : {
          "type" "comments",
          "inner_hits" : {}
      }
}

```

This will include per post hit the top 3 matching comment hits.

---

<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:** [May 19, 2017, 7:21am UTC](https://discuss.elastic.co/t/get-both-parent-and-child-document/82862/3 "2017-05-19T07:21:37Z")

</div>

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