# Get Count Using has-child query

**URL:** <https://discuss.elastic.co/t/get-count-using-has-child-query/3763>\
**Category:** Elasticsearch\
**Created:** [January 11, 2011, 8:42am UTC](https://discuss.elastic.co/t/get-count-using-has-child-query/3763 "2011-01-11T08:42:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arulkumar](https://avatars.discourse-cdn.com/v4/letter/a/6de8d8/32.png) [@Arulkumar](https://discuss.elastic.co/u/Arulkumar)\
**Post date:** [January 11, 2011, 8:42am UTC](https://discuss.elastic.co/t/get-count-using-has-child-query/3763/1 "2011-01-11T08:42:42Z")

</div>

Hi ,

1. How to get document count in an index using child query.?

{"count":0,"\_shards":{"total":2,"successful":0,"failed":2,"failures":  
[{"index":"dbtest","shard":  
0,"reason":"BroadcastShardOperationFailedException[[dbtest]0] ];  
nested:"},{"index":"dbtest","shard":  
1,"reason":"BroadcastShardOperationFailedException[[dbtest]1] ];  
nested: "}]}}

Can any one help me.........

---

<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:** [January 11, 2011, 8:01pm UTC](https://discuss.elastic.co/t/get-count-using-has-child-query/3763/2 "2011-01-11T20:01:04Z")

</div>

Count API does not support child query, just issue a search request with 0 size and look at the total hits.  
On Tuesday, January 11, 2011 at 10:42 AM, Arulkumar wrote:

> Hi ,
> 
> 1. How to get document count in an index using child query.?
> 
> I am using the query to get count is......
> 
> curl -XGET '[http://localhost:9200/dbtest/parent/\_count](http://localhost:9200/dbtest/parent/_count)' -d  
> '{"has\_child" : {"type" : "child", "query" :{ "term" :  
> { "myfield": "test" } }} }'
> 
> But i am getting like this...........
> 
> {"count":0,"\_shards":{"total":2,"successful":0,"failed":2,"failures":  
> [{"index":"dbtest","shard":  
> 0,"reason":"BroadcastShardOperationFailedException[[dbtest]0] ];  
> nested:"},{"index":"dbtest","shard":  
> 1,"reason":"BroadcastShardOperationFailedException[[dbtest]1] ];  
> nested: "}]}}
> 
> Can any one help me.........

---

<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:** [January 11, 2011, 8:05pm UTC](https://discuss.elastic.co/t/get-count-using-has-child-query/3763/3 "2011-01-11T20:05:14Z")

</div>

ok, pushed support for it: [Shared Gateway: Allow to set the number of concurrent streams doing snapshot operations · Issue #621 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/issue/621).  
On Tuesday, January 11, 2011 at 10:01 PM, Shay Banon wrote:

> Count API does not support child query, just issue a search request with 0 size and look at the total hits.  
> On Tuesday, January 11, 2011 at 10:42 AM, Arulkumar wrote:
> 
> > Hi ,
> > 
> > 1. How to get document count in an index using child query.?
> > 
> > I am using the query to get count is......
> > 
> > curl -XGET '[http://localhost:9200/dbtest/parent/\_count](http://localhost:9200/dbtest/parent/_count)' -d  
> > '{"has\_child" : {"type" : "child", "query" :{ "term" :  
> > { "myfield": "test" } }} }'
> > 
> > But i am getting like this...........
> > 
> > {"count":0,"\_shards":{"total":2,"successful":0,"failed":2,"failures":  
> > [{"index":"dbtest","shard":  
> > 0,"reason":"BroadcastShardOperationFailedException[[dbtest]0] ];  
> > nested:"},{"index":"dbtest","shard":  
> > 1,"reason":"BroadcastShardOperationFailedException[[dbtest]1] ];  
> > nested: "}]}}
> > 
> > Can any one help me.........

---

<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:** [January 12, 2011, 7:23pm UTC](https://discuss.elastic.co/t/get-count-using-has-child-query/3763/4 "2011-01-12T19:23:37Z")

</div>

Oops, wrong reply to, this change is not related to this...  
On Tuesday, January 11, 2011 at 10:05 PM, Shay Banon wrote:

> ok, pushed support for it: [Shared Gateway: Allow to set the number of concurrent streams doing snapshot operations · Issue #621 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/issue/621).  
> On Tuesday, January 11, 2011 at 10:01 PM, Shay Banon wrote:
> 
> > Count API does not support child query, just issue a search request with 0 size and look at the total hits.  
> > On Tuesday, January 11, 2011 at 10:42 AM, Arulkumar wrote:
> > 
> > > Hi ,
> > > 
> > > 1. How to get document count in an index using child query.?
> > > 
> > > I am using the query to get count is......
> > > 
> > > curl -XGET '[http://localhost:9200/dbtest/parent/\_count](http://localhost:9200/dbtest/parent/_count)' -d  
> > > '{"has\_child" : {"type" : "child", "query" :{ "term" :  
> > > { "myfield": "test" } }} }'
> > > 
> > > But i am getting like this...........
> > > 
> > > {"count":0,"\_shards":{"total":2,"successful":0,"failed":2,"failures":  
> > > [{"index":"dbtest","shard":  
> > > 0,"reason":"BroadcastShardOperationFailedException[[dbtest]0] ];  
> > > nested:"},{"index":"dbtest","shard":  
> > > 1,"reason":"BroadcastShardOperationFailedException[[dbtest]1] ];  
> > > nested: "}]}}
> > > 
> > > Can any one help me.........

---

<div class="post-metadata">

**Author:** ![Arulkumar](https://avatars.discourse-cdn.com/v4/letter/a/6de8d8/32.png) [@Arulkumar](https://discuss.elastic.co/u/Arulkumar)\
**Post date:** [January 13, 2011, 8:38am UTC](https://discuss.elastic.co/t/get-count-using-has-child-query/3763/5 "2011-01-13T08:38:13Z")

</div>

thank you shay......

On Jan 13, 12:23 am, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> Oops, wrong reply to, this change is not related to this...
> 
> On Tuesday, January 11, 2011 at 10:05 PM, Shay Banon wrote:
> 
> > ok, pushed support for it:[Shared Gateway: Allow to set the number of concurrent streams doing snapshot operations · Issue #621 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/issue/621).  
> > On Tuesday, January 11, 2011 at 10:01 PM, Shay Banon wrote:
> 
> > > Count API does not support child query, just issue a search request with 0 size and look at the total hits.  
> > > On Tuesday, January 11, 2011 at 10:42 AM, Arulkumar wrote:
> 
> > > > Hi ,
> 
> > > > 1. How to get document count in an index using child query.?
> 
> > > > I am using the query to get count is......
> 
> > > > curl -XGET '[http://localhost:9200/dbtest/parent/\_count'-d](http://localhost:9200/dbtest/parent/_count'-d)  
> > > > '{"has\_child" : {"type" : "child", "query" :{ "term" :  
> > > > { "myfield": "test" } }} }'
> 
> > > > But i am getting like this...........
> 
> > > > {"count":0,"\_shards":{"total":2,"successful":0,"failed":2,"failures":  
> > > > [{"index":"dbtest","shard":  
> > > > 0,"reason":"BroadcastShardOperationFailedException[[dbtest]0] ];  
> > > > nested:"},{"index":"dbtest","shard":  
> > > > 1,"reason":"BroadcastShardOperationFailedException[[dbtest]1] ];  
> > > > nested: "}]}}
> 
> > > > Can any one help me.........

---

<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:13am UTC](https://discuss.elastic.co/t/get-count-using-has-child-query/3763/6 "2017-07-06T04:13:57Z")

</div>


