# How to query document to return parent and child result

**URL:** https://discuss.elastic.co/t/how-to-query-document-to-return-parent-and-child-result/13223
**Category:** Elasticsearch
**Created:** [August 15, 2013, 3:37am UTC](https://discuss.elastic.co/t/how-to-query-document-to-return-parent-and-child-result/13223 "2013-08-15T03:37:28Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![cyrilforce](https://avatars.discourse-cdn.com/v4/letter/c/76d3ee/32.png) [@cyrilforce](https://discuss.elastic.co/u/cyrilforce)
#### Post date: [August 15, 2013, 3:37am UTC](https://discuss.elastic.co/t/how-to-query-document-to-return-parent-and-child-result/13223/1 "2013-08-15T03:37:28Z")

</div>

Hi All,

I have created some parent and child documents :

curl -XPUT '[http://localhost:9200/twitter/author/1](http://localhost:9200/twitter/author/1) -d'  
curl -XPUT '[http://localhost:9200/twitter/author/2](http://localhost:9200/twitter/author/2) -d'

curl -XPUT '[http://localhost:9200/twitter/tweet/1?parent=1](http://localhost:9200/twitter/tweet/1?parent=1) -d'  
curl -XPUT '[http://localhost:9200/twitter/tweet/2?parent=2](http://localhost:9200/twitter/tweet/2?parent=2) -d'

with the mapping as well. However there is a case whereby i need to query  
the parent and child with the result return with both parent and child  
information. I would like to know could i  
achieve that in a single query or i need to do 2 query each for parent and  
child.

Thanks.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Atul\_Bagga](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/atul_bagga/32/15047_2.png) [@Atul\_Bagga](https://discuss.elastic.co/u/Atul_Bagga)
#### Post date: [March 2, 2017, 11:51am UTC](https://discuss.elastic.co/t/how-to-query-document-to-return-parent-and-child-result/13223/2 "2017-03-02T11:51:27Z")

</div>

Did you get an answer to this? I also have a similar requirement.

I want to query such that Parent should derive its relevance from both itself and all Child documents and I want to show parent and child items in search result.

---

<div class="post-metadata">

### Author: ![Atul\_Bagga](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/atul_bagga/32/15047_2.png) [@Atul\_Bagga](https://discuss.elastic.co/u/Atul_Bagga)
#### Post date: [March 2, 2017, 1:17pm UTC](https://discuss.elastic.co/t/how-to-query-document-to-return-parent-and-child-result/13223/3 "2017-03-02T13:17:00Z")

</div>

Actually I found this thread now which is helpful on this-

> [@Querying both parent as child document fields](https://discuss.elastic.co/t/querying-both-parent-as-child-document-fields/12019):
>
> Hello, I'm struggling a bit to write a query that would query fields on a parent document and the fields on a child document. first thought, my mapping: I have documents of type 'resource' (these are the parent docs) which have a couple of fields, the ones I'll be querying are called 'q\_high' and 'q\_low'. I also have documents of type 'message' (the child documents) which have the same q\_high and q\_low fields We've modelled it this way as all top level resources can have messages assoc…

---

<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, 10:02pm UTC](https://discuss.elastic.co/t/how-to-query-document-to-return-parent-and-child-result/13223/4 "2017-07-05T22:02:42Z")

</div>


