# Nested hasChildQuery

**URL:** https://discuss.elastic.co/t/nested-haschildquery/6799
**Category:** Elasticsearch
**Created:** [February 24, 2012, 12:36pm UTC](https://discuss.elastic.co/t/nested-haschildquery/6799 "2012-02-24T12:36:13Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![SK1](https://avatars.discourse-cdn.com/v4/letter/s/7ba0ec/32.png) [@SK1](https://discuss.elastic.co/u/SK1)
#### Post date: [February 24, 2012, 12:36pm UTC](https://discuss.elastic.co/t/nested-haschildquery/6799/1 "2012-02-24T12:36:13Z")

</div>

Hi all,

Context: Java api, ES 0.18.7

I'm trying to run the following query but with no success.

hasChildQuery("line", hasChildQuery("item", termQuery("value", 1))

Is there any logical reason againt using nested hasChildQuery queries?

Searching for both individually works fine returning each time the  
correct parents. I assumed that combining the two would result in the  
most upper parent returned as result.

The types are put in the index like this:

line: {"type":{"\_parent":{"type":"plant"}}}

item: {"type":{"\_parent":{"type":"line"}}}

Any ideas?

---

<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: [February 26, 2012, 7:30pm UTC](https://discuss.elastic.co/t/nested-haschildquery/6799/2 "2012-02-26T19:30:20Z")

</div>

Yes, it should work.

On Friday, February 24, 2012 at 2:36 PM, SK wrote:

> Hi all,
> 
> Context: Java api, ES 0.18.7
> 
> I'm trying to run the following query but with no success.
> 
> hasChildQuery("line", hasChildQuery("item", termQuery("value", 1))
> 
> Is there any logical reason againt using nested hasChildQuery queries?
> 
> Searching for both individually works fine returning each time the  
> correct parents. I assumed that combining the two would result in the  
> most upper parent returned as result.
> 
> The types are put in the index like this:
> 
> line: {"type":{"\_parent":{"type":"plant"}}}
> 
> item: {"type":{"\_parent":{"type":"line"}}}
> 
> Any ideas?

---

<div class="post-metadata">

### Author: ![SK1](https://avatars.discourse-cdn.com/v4/letter/s/7ba0ec/32.png) [@SK1](https://discuss.elastic.co/u/SK1)
#### Post date: [March 2, 2012, 7:16am UTC](https://discuss.elastic.co/t/nested-haschildquery/6799/3 "2012-03-02T07:16:53Z")

</div>

was solved with [Multi level parent/child mapping and search fails · Issue #1751 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/1751)

Thanks

On Feb 26, 8:30 pm, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> Yes, it should work.
> 
> On Friday, February 24, 2012 at 2:36 PM, SK wrote:
> 
> > Hi all,
> 
> > Context: Java api, ES 0.18.7
> 
> > I'm trying to run the following query but with no success.
> 
> > hasChildQuery("line", hasChildQuery("item", termQuery("value", 1))
> 
> > Is there any logical reason againt using nested hasChildQuery queries?
> 
> > Searching for both individually works fine returning each time the  
> > correct parents. I assumed that combining the two would result in the  
> > most upper parent returned as result.
> 
> > The types are put in the index like this:
> 
> > line: {"type":{"\_parent":{"type":"plant"}}}
> 
> > item: {"type":{"\_parent":{"type":"line"}}}
> 
> > Any ideas?

---

<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: [March 3, 2012, 9:54pm UTC](https://discuss.elastic.co/t/nested-haschildquery/6799/4 "2012-03-03T21:54:28Z")

</div>

Yea, it didn't work…, but it does now (0.19).

On Friday, February 24, 2012 at 2:36 PM, SK wrote:

> Hi all,
> 
> Context: Java api, ES 0.18.7
> 
> I'm trying to run the following query but with no success.
> 
> hasChildQuery("line", hasChildQuery("item", termQuery("value", 1))
> 
> Is there any logical reason againt using nested hasChildQuery queries?
> 
> Searching for both individually works fine returning each time the  
> correct parents. I assumed that combining the two would result in the  
> most upper parent returned as result.
> 
> The types are put in the index like this:
> 
> line: {"type":{"\_parent":{"type":"plant"}}}
> 
> item: {"type":{"\_parent":{"type":"line"}}}
> 
> Any ideas?

---

<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:37am UTC](https://discuss.elastic.co/t/nested-haschildquery/6799/5 "2017-07-06T03:37:28Z")

</div>


