# Count operation with hasChild filter doesn't work

**URL:** <https://discuss.elastic.co/t/count-operation-with-haschild-filter-doesnt-work/5839>\
**Category:** Elasticsearch\
**Created:** [November 10, 2011, 5:40pm UTC](https://discuss.elastic.co/t/count-operation-with-haschild-filter-doesnt-work/5839 "2011-11-10T17:40:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wojciech\_Durczynski](https://avatars.discourse-cdn.com/v4/letter/w/fbc32d/32.png) [@Wojciech\_Durczynski](https://discuss.elastic.co/u/Wojciech_Durczynski)\
**Post date:** [November 10, 2011, 5:40pm UTC](https://discuss.elastic.co/t/count-operation-with-haschild-filter-doesnt-work/5839/1 "2011-11-10T17:40:48Z")

</div>

Hello.

If I query from parent type using hasChild filter, there are no problems.  
Everything works as expected.  
But if I do a count request with the same hasChild filter, then there is a  
problem:  
Type [myChildType] does not have parent mapping.

There is a workaround for this: use query instead of count and use total  
count returned, but this isn't optimal solution of course:)

Regards  
Wojciech Durczyński

---

<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:** [November 13, 2011, 7:09am UTC](https://discuss.elastic.co/t/count-operation-with-haschild-filter-doesnt-work/5839/2 "2011-11-13T07:09:25Z")

</div>

Yes, its not supported. Use search\_type=count and do a regular search, it  
is as fast as the count endpoint.

2011/11/10 Wojciech Durczyński [wojciech.durczynski@comarch.com](mailto:wojciech.durczynski@comarch.com)

> Hello.
> 
> If I query from parent type using hasChild filter, there are no problems.  
> Everything works as expected.  
> But if I do a count request with the same hasChild filter, then there is a  
> problem:  
> Type [myChildType] does not have parent mapping.
> 
> There is a workaround for this: use query instead of count and use total  
> count returned, but this isn't optimal solution of course:)
> 
> Regards  
> Wojciech Durczyński

---

<div class="post-metadata">

**Author:** ![btiernay](https://avatars.discourse-cdn.com/v4/letter/b/bb73d2/32.png) [@btiernay](https://discuss.elastic.co/u/btiernay)\
**Post date:** [May 3, 2013, 3:40pm UTC](https://discuss.elastic.co/t/count-operation-with-haschild-filter-doesnt-work/5839/3 "2013-05-03T15:40:55Z")

</div>

Hey Shay,

Could you please explain why the count would be just as fast as a query? Is  
that because count is implemented as a query and is just a convenience  
operation?

Thanks

On Sunday, 13 November 2011 02:09:25 UTC-5, kimchy wrote:

> Yes, its not supported. Use search\_type=count and do a regular search, it  
> is as fast as the count endpoint.
> 
> 2011/11/10 Wojciech Durczyński \<[wojciech....@comarch.com](mailto:wojciech....@comarch.com) \<javascript:\>\>
> 
> > Hello.
> > 
> > If I query from parent type using hasChild filter, there are no problems.  
> > Everything works as expected.  
> > But if I do a count request with the same hasChild filter, then there is  
> > a problem:  
> > Type [myChildType] does not have parent mapping.
> > 
> > There is a workaround for this: use query instead of count and use total  
> > count returned, but this isn't optimal solution of course:)
> > 
> > Regards  
> > Wojciech Durczyński

--  
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:** ![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, 2:38am UTC](https://discuss.elastic.co/t/count-operation-with-haschild-filter-doesnt-work/5839/4 "2017-07-06T02:38:28Z")

</div>


