# Top\_children and has\_child together in query

**URL:** https://discuss.elastic.co/t/top-children-and-has-child-together-in-query/4523
**Category:** Elasticsearch
**Created:** [June 1, 2011, 7:37pm UTC](https://discuss.elastic.co/t/top-children-and-has-child-together-in-query/4523 "2011-06-01T19:37:41Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![deepakkhajuria](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@deepakkhajuria](https://discuss.elastic.co/u/deepakkhajuria)
#### Post date: [June 1, 2011, 7:37pm UTC](https://discuss.elastic.co/t/top-children-and-has-child-together-in-query/4523/1 "2011-06-01T19:37:41Z")

</div>

Hi,

I have three level schema for index which is like:

conversation  
|----message  
|-------message\_tag

Now if run following query on _message_, it returns results  
correctly.  
  
_{  
"query": {  
"has\_child": {  
"type": "message",  
"query": {  
"match\_all": {}  
}  
}  
}  
}_

Now if I put query above in query part of top\_children on  
conversation, it does not return anything and returns some errors with  
200. I am trying to get top conversations with messages having  
children.  
_{  
"query": {  
"top\_children": {  
"type": "message",  
"score": "sum",  
"query": {  
"has\_child": {  
"type": "message\_tag",  
"query": {  
"match\_all": {}  
}  
}  
}  
}  
}  
}_

Results:  
_{"took":3,"timed\_out":false,"\_shards":{"total":5,"successful":  
3,"failed":2,"failures":[{"index":"testcompany","shard":  
0,"reason":"QueryPhaseExecutionException[[testcompany][0]:  
query[score\_child[message/conversation]  
(filtered(ConstantScore(child\_filter[message\_tag/message]  
(filtered(ConstantScore(:))-_

 

> _FilterCacheFilterWrapper(\_type:message\_tag))))-  
> FilterCacheFilterWrapper(\_type:message))],from[0],size[10]: Query  
> Failed [Failed to execute child query [score\_child[message/  
> conversation](filtered(ConstantScore(child\_filter[message\_tag/message]  
> (filtered(ConstantScore(:))-  
> FilterCacheFilterWrapper(\_type:message\_tag))))-  
> FilterCacheFilterWrapper(\_type:message))]]]; nested: "},  
> {"index":"testcompany","shard":  
> 1,"reason":"QueryPhaseExecutionException[[testcompany][1]:  
> query[score\_child[message/conversation]  
> (filtered(ConstantScore(child\_filter[message\_tag/message]  
> (filtered(ConstantScore(:))-  
> FilterCacheFilterWrapper(\_type:message\_tag))))-  
> FilterCacheFilterWrapper(\_type:message))],from[0],size[10]: Query  
> Failed [Failed to execute child query [score\_child[message/  
> conversation](filtered(ConstantScore(child\_filter[message\_tag/message]  
> (filtered(ConstantScore(:))-  
> FilterCacheFilterWrapper(\_type:message\_tag))))-  
> FilterCacheFilterWrapper(\_type:message))]]]; nested: "}]},"hits":  
> {"total":0,"max\_score":null,"hits":}}_

I am new to Elasticsearch, so is this supposed to work or I am doing  
something wrong.

Thanks,  
Deepak

---

<div class="post-metadata">

### Author: ![deepakkhajuria](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@deepakkhajuria](https://discuss.elastic.co/u/deepakkhajuria)
#### Post date: [June 1, 2011, 7:57pm UTC](https://discuss.elastic.co/t/top-children-and-has-child-together-in-query/4523/2 "2011-06-01T19:57:08Z")

</div>

Sorry for typo:  
the first query is

{  
"query": {  
"has\_child": {  
"type": "message\_tag",  
"query": {  
"match\_all": {}  
}  
}  
}

On Jun 1, 12:37 pm, deepakkhajuria [deep...@gmail.com](mailto:deep...@gmail.com) wrote:

> Hi,
> 
> I have three level schema for index which is like:
> 
> conversation  
> |----message  
> |-------message\_tag
> 
> Now if run following query on _message_, it returns results  
> correctly.  
>   
> _{  
> "query": {  
> "has\_child": {  
> "type": "message",  
> "query": {  
> "match\_all": {}  
> }  
> }  
> }_
> 
>  
> 
> _}_
> 
> Now if I put query above in query part of top\_children on  
> conversation, it does not return anything and returns some errors with  
> 200. I am trying to get top conversations with messages having  
> children.  
> _{  
> "query": {  
> "top\_children": {  
> "type": "message",  
> "score": "sum",  
> "query": {  
> "has\_child": {  
> "type": "message\_tag",  
> "query": {  
> "match\_all": {}  
> }  
> }  
> }  
> }  
> }_
> 
>  
> 
> _}_
> 
> Results:  
> _{"took":3,"timed\_out":false,"\_shards":{"total":5,"successful":  
> 3,"failed":2,"failures":[{"index":"testcompany","shard":  
> 0,"reason":"QueryPhaseExecutionException[[testcompany][0]:  
> query[score\_child[message/conversation]  
> (filtered(ConstantScore(child\_filter[message\_tag/message]  
> (filtered(ConstantScore(:))-\>FilterCacheFilterWrapper(\_type:message\_tag))))-_
> 
>  
> 
> _> FilterCacheFilterWrapper(\_type:message))],from[0],size[10]: Query_
> 
>  
> 
> Failed [Failed to execute child query [score\_child[message/  
> conversation](filtered(ConstantScore(child\_filter[message\_tag/message]  
> (filtered(ConstantScore(_:_))-\>FilterCacheFilterWrapper(\_type:message\_tag))))-
> 
> > FilterCacheFilterWrapper(\_type:message))]]]; nested: "},
> 
> {"index":"testcompany","shard":  
> 1,"reason":"QueryPhaseExecutionException[[testcompany][1]:  
> query[score\_child[message/conversation]  
> (filtered(ConstantScore(child\_filter[message\_tag/message]  
> (filtered(ConstantScore(_:_))-\>FilterCacheFilterWrapper(\_type:message\_tag))))-
> 
> > FilterCacheFilterWrapper(\_type:message))],from[0],size[10]: Query
> 
> Failed [Failed to execute child query [score\_child[message/  
> conversation](filtered(ConstantScore(child\_filter[message\_tag/message]  
> (filtered(ConstantScore(_:_))-\>FilterCacheFilterWrapper(\_type:message\_tag))))-
> 
> > FilterCacheFilterWrapper(\_type:message))]]]; nested: "}]},"hits":
> 
> _{"total":0,"max\_score":null,"hits":}}_
> 
> I am new to Elasticsearch, so is this supposed to work or I am doing  
> something wrong.
> 
> Thanks,  
> Deepak

---

<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: [June 2, 2011, 7:29am UTC](https://discuss.elastic.co/t/top-children-and-has-child-together-in-query/4523/3 "2011-06-02T07:29:40Z")

</div>

Did not fully understand what you execute, can you gist a full sample? See [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/help).

On Wednesday, June 1, 2011 at 10:57 PM, deepakkhajuria wrote:

> Sorry for typo:  
> the first query is
> 
> {  
> "query": {  
> "has\_child": {  
> "type": "message\_tag",  
> "query": {  
> "match\_all": {}  
> }  
> }  
> }
> 
> On Jun 1, 12:37 pm, deepakkhajuria \<[deep...@gmail.com](mailto:deep...@gmail.com) ([http://gmail.com](http://gmail.com))\> wrote:
> 
> > Hi,
> > 
> > I have three level schema for index which is like:
> > 
> > conversation  
> > |----message  
> > |-------message\_tag
> > 
> > Now if run following query on _message_, it returns results  
> > correctly.  
> >   
> > _{  
> > "query": {  
> > "has\_child": {  
> > "type": "message",  
> > "query": {  
> > "match\_all": {}  
> > }  
> > }  
> > }_
> > 
> >  
> > 
> > _}_
> > 
> > Now if I put query above in query part of top\_children on  
> > conversation, it does not return anything and returns some errors with  
> > 200. I am trying to get top conversations with messages having  
> > children.  
> > _{  
> > "query": {  
> > "top\_children": {  
> > "type": "message",  
> > "score": "sum",  
> > "query": {  
> > "has\_child": {  
> > "type": "message\_tag",  
> > "query": {  
> > "match\_all": {}  
> > }  
> > }  
> > }  
> > }  
> > }_
> > 
> >  
> > 
> > _}_
> > 
> > Results:  
> > _{"took":3,"timed\_out":false,"\_shards":{"total":5,"successful":  
> > 3,"failed":2,"failures":[{"index":"testcompany","shard":  
> > 0,"reason":"QueryPhaseExecutionException[[testcompany][0]:  
> > query[score\_child[message/conversation]  
> > (filtered(ConstantScore(child\_filter[message\_tag/message]  
> > (filtered(ConstantScore(:))-\>FilterCacheFilterWrapper(\_type:message\_tag))))-_
> > 
> >  
> > 
> > _> FilterCacheFilterWrapper(\_type:message))],from[0],size[10]: Query_
> > 
> >  
> > 
> > Failed [Failed to execute child query [score\_child[message/  
> > conversation](filtered(ConstantScore(child\_filter[message\_tag/message]  
> > (filtered(ConstantScore(_:_))-\>FilterCacheFilterWrapper(\_type:message\_tag))))-
> > 
> > > FilterCacheFilterWrapper(\_type:message))]]]; nested: "},
> > 
> > {"index":"testcompany","shard":  
> > 1,"reason":"QueryPhaseExecutionException[[testcompany][1]:  
> > query[score\_child[message/conversation]  
> > (filtered(ConstantScore(child\_filter[message\_tag/message]  
> > (filtered(ConstantScore(_:_))-\>FilterCacheFilterWrapper(\_type:message\_tag))))-
> > 
> > > FilterCacheFilterWrapper(\_type:message))],from[0],size[10]: Query
> > 
> > Failed [Failed to execute child query [score\_child[message/  
> > conversation](filtered(ConstantScore(child\_filter[message\_tag/message]  
> > (filtered(ConstantScore(_:_))-\>FilterCacheFilterWrapper(\_type:message\_tag))))-
> > 
> > > FilterCacheFilterWrapper(\_type:message))]]]; nested: "}]},"hits":
> > 
> > _{"total":0,"max\_score":null,"hits":}}_
> > 
> > I am new to Elasticsearch, so is this supposed to work or I am doing  
> > something wrong.
> > 
> > Thanks,  
> > Deepak

---

<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, 4:04am UTC](https://discuss.elastic.co/t/top-children-and-has-child-together-in-query/4523/4 "2017-07-06T04:04:57Z")

</div>


