# Retrieve children docs only

**URL:** <https://discuss.elastic.co/t/retrieve-children-docs-only/5185>\
**Category:** Elasticsearch\
**Created:** [August 17, 2011, 11:55am UTC](https://discuss.elastic.co/t/retrieve-children-docs-only/5185 "2011-08-17T11:55:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![avasilenko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/avasilenko/32/2901_2.png) [@avasilenko](https://discuss.elastic.co/u/avasilenko)\
**Post date:** [August 17, 2011, 11:55am UTC](https://discuss.elastic.co/t/retrieve-children-docs-only/5185/1 "2011-08-17T11:55:39Z")

</div>

Hello,

Duplicating post from nabble, as it didn't dupicate it here.  
I have 1 index **object** with 2 types: _entity_ and _shop\</  
i\>. Object shop is child of object entity and has following mapping.  
Sending [this query](https://gist.github.com/1151361) to  
object/\_search returns me the child doc only, which is ok, as I can  
manually join it.  
But, when I add term for parent doc, I receive parent doc only as a  
search hit. [Query example\</  
a\>.](https://gist.github.com/1151366)_

Since according to the docs there is no way to perform parent and  
child join, can I at least fetch child docs with search conditions  
specified for both parent and child?

Regards,  
Alex

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [August 18, 2011, 12:12pm UTC](https://discuss.elastic.co/t/retrieve-children-docs-only/5185/2 "2011-08-18T12:12:00Z")

</div>

Not sure I fully understand, but, when you execute a has\_child query, you  
get back only the parent docs.

On Wed, Aug 17, 2011 at 2:55 PM, Alex Vasilenko [aa.vasilenko@gmail.com](mailto:aa.vasilenko@gmail.com)wrote:

> Hello,
> 
> Duplicating post from nabble, as it didn't dupicate it here.  
> I have 1 index **object** with 2 types: _entity_ and _shop\</  
> i\>. Object shop is child of object entity and has following mapping.  
> Sending [this query](https://gist.github.com/1151361) to  
> object/\_search returns me the child doc only, which is ok, as I can  
> manually join it.  
> But, when I add term for parent doc, I receive parent doc only as a  
> search hit. [Query example\</  
> a\>.](https://gist.github.com/1151366)_
> 
> _[_ 
> 
> _Since according to the docs there is no way to perform parent and  
> child join, can I at least fetch child docs with search conditions  
> specified for both parent and child?_
> 
>  
> 
> _Regards,  
> Alex_
> 
> _](https://gist.github.com/1151366)_

---

<div class="post-metadata">

**Author:** ![avasilenko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/avasilenko/32/2901_2.png) [@avasilenko](https://discuss.elastic.co/u/avasilenko)\
**Post date:** [August 18, 2011, 12:33pm UTC](https://discuss.elastic.co/t/retrieve-children-docs-only/5185/3 "2011-08-18T12:33:18Z")

</div>

In general the question is:  
How can I search both in parent and child docs and retrieve child docs?

2011/8/18 Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com)

> Not sure I fully understand, but, when you execute a has\_child query, you  
> get back only the parent docs.
> 
> On Wed, Aug 17, 2011 at 2:55 PM, Alex Vasilenko [aa.vasilenko@gmail.com](mailto:aa.vasilenko@gmail.com)wrote:
> 
> > Hello,
> > 
> > Duplicating post from nabble, as it didn't dupicate it here.  
> > I have 1 index **object** with 2 types: _entity_ and _shop\</  
> > i\>. Object shop is child of object entity and has following mapping.  
> > Sending [this query](https://gist.github.com/1151361) to  
> > object/\_search returns me the child doc only, which is ok, as I can  
> > manually join it.  
> > But, when I add term for parent doc, I receive parent doc only as a  
> > search hit. [Query example\</  
> > a\>.](https://gist.github.com/1151366)_
> > 
> > _[_ 
> > 
> > _Since according to the docs there is no way to perform parent and  
> > child join, can I at least fetch child docs with search conditions  
> > specified for both parent and child?_
> > 
> >  
> > 
> > _Regards,  
> > Alex_
> > 
> > _](https://gist.github.com/1151366)_
> 
> _[](https://gist.github.com/1151366)_

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [August 19, 2011, 4:35am UTC](https://discuss.elastic.co/t/retrieve-children-docs-only/5185/4 "2011-08-19T04:35:46Z")

</div>

You can search child docs since they are just docs, and then retried them.  
But that means you can only search on data associated with the child docs.  
If you also want to search on parent data, then you will only get back  
parent docs. You can go and get child docs associated with parent docs, that  
that won't "filter" out possibly matching child docs.

On Thu, Aug 18, 2011 at 3:33 PM, Alex Vasilenko [aa.vasilenko@gmail.com](mailto:aa.vasilenko@gmail.com)wrote:

> In general the question is:  
> How can I search both in parent and child docs and retrieve child docs?
> 
> 2011/8/18 Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com)
> 
> > Not sure I fully understand, but, when you execute a has\_child query, you  
> > get back only the parent docs.
> > 
> > On Wed, Aug 17, 2011 at 2:55 PM, Alex Vasilenko [aa.vasilenko@gmail.com](mailto:aa.vasilenko@gmail.com)wrote:
> > 
> > > Hello,
> > > 
> > > Duplicating post from nabble, as it didn't dupicate it here.  
> > > I have 1 index **object** with 2 types: _entity_ and _shop\</  
> > > i\>. Object shop is child of object entity and has following mapping.  
> > > Sending [this query](https://gist.github.com/1151361) to  
> > > object/\_search returns me the child doc only, which is ok, as I can  
> > > manually join it.  
> > > But, when I add term for parent doc, I receive parent doc only as a  
> > > search hit. [Query example\</  
> > > a\>.](https://gist.github.com/1151366)_
> > > 
> > > _[_ 
> > > 
> > > _Since according to the docs there is no way to perform parent and  
> > > child join, can I at least fetch child docs with search conditions  
> > > specified for both parent and child?_
> > > 
> > >  
> > > 
> > > _Regards,  
> > > Alex_
> > > 
> > > _](https://gist.github.com/1151366)_
> > 
> > _[](https://gist.github.com/1151366)_
> 
> _[](https://gist.github.com/1151366)_

---

<div class="post-metadata">

**Author:** ![avasilenko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/avasilenko/32/2901_2.png) [@avasilenko](https://discuss.elastic.co/u/avasilenko)\
**Post date:** [August 19, 2011, 7:27am UTC](https://discuss.elastic.co/t/retrieve-children-docs-only/5185/5 "2011-08-19T07:27:37Z")

</div>

So it can be done in 2 queries:  
1st one - both on parent and child, retrieving parent only  
2nd one - in order to retrieve childs, associated with parent. What query to  
use? Filter terms on \_parent field, listing all found ids?

2011/8/19 Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com)

> You can search child docs since they are just docs, and then retried them.  
> But that means you can only search on data associated with the child docs.  
> If you also want to search on parent data, then you will only get back  
> parent docs. You can go and get child docs associated with parent docs, that  
> that won't "filter" out possibly matching child docs.
> 
> On Thu, Aug 18, 2011 at 3:33 PM, Alex Vasilenko [aa.vasilenko@gmail.com](mailto:aa.vasilenko@gmail.com)wrote:
> 
> > In general the question is:  
> > How can I search both in parent and child docs and retrieve child docs?
> > 
> > 2011/8/18 Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com)
> > 
> > > Not sure I fully understand, but, when you execute a has\_child query, you  
> > > get back only the parent docs.
> > > 
> > > On Wed, Aug 17, 2011 at 2:55 PM, Alex Vasilenko [aa.vasilenko@gmail.com](mailto:aa.vasilenko@gmail.com)wrote:
> > > 
> > > > Hello,
> > > > 
> > > > Duplicating post from nabble, as it didn't dupicate it here.  
> > > > I have 1 index **object** with 2 types: _entity_ and _shop\</  
> > > > i\>. Object shop is child of object entity and has following mapping.  
> > > > Sending [this query](https://gist.github.com/1151361) to  
> > > > object/\_search returns me the child doc only, which is ok, as I can  
> > > > manually join it.  
> > > > But, when I add term for parent doc, I receive parent doc only as a  
> > > > search hit. [Query example\</  
> > > > a\>.](https://gist.github.com/1151366)_
> > > > 
> > > > _[_ 
> > > > 
> > > > _Since according to the docs there is no way to perform parent and  
> > > > child join, can I at least fetch child docs with search conditions  
> > > > specified for both parent and child?_
> > > > 
> > > >  
> > > > 
> > > > _Regards,  
> > > > Alex_
> > > > 
> > > > _](https://gist.github.com/1151366)_
> > > 
> > > _[](https://gist.github.com/1151366)_
> > 
> > _[](https://gist.github.com/1151366)_
> 
> _[](https://gist.github.com/1151366)_

---

<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 6, 2017, 3:56am UTC](https://discuss.elastic.co/t/retrieve-children-docs-only/5185/6 "2017-07-06T03:56:35Z")

</div>


