# Count versus Search API

**URL:** <https://discuss.elastic.co/t/count-versus-search-api/15981>\
**Category:** Elasticsearch\
**Created:** [February 24, 2014, 3:51am UTC](https://discuss.elastic.co/t/count-versus-search-api/15981 "2014-02-24T03:51:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pulkitsinghal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pulkitsinghal/32/802_2.png) [@pulkitsinghal](https://discuss.elastic.co/u/pulkitsinghal)\
**Post date:** [February 24, 2014, 3:51am UTC](https://discuss.elastic.co/t/count-versus-search-api/15981/1 "2014-02-24T03:51:43Z")

</div>

Hello,

I have a bool query with a filter applied to it, which runs against the  
\_search endpoint successfully giving "hits.total" but unfortunately it also  
gives a lot more data than that which I don't need.

So I thought of running the same query against the \_count endpoint but  
there I received a  
failure: "BroadcastShardOperationFailedException[[index\_test][0] ]; nested:  
QueryParsingException[[index\_test] No query registered for [query]]; "

Is there some other lightweight manner in which I can get just "hits.total"  
without the added bloat of each matching doc?

Thanks!

- Pulkit

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/a1c1e381-3464-4932-8114-977b2e01c304%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/a1c1e381-3464-4932-8114-977b2e01c304%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 24, 2014, 6:38am UTC](https://discuss.elastic.co/t/count-versus-search-api/15981/2 "2014-02-24T06:38:20Z")

</div>

How does your count query look like?

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 24 févr. 2014 à 04:51, pulkitsinghal [pulkitsinghal@gmail.com](mailto:pulkitsinghal@gmail.com) a écrit :

Hello,

I have a bool query with a filter applied to it, which runs against the \_search endpoint successfully giving "hits.total" but unfortunately it also gives a lot more data than that which I don't need.

So I thought of running the same query against the \_count endpoint but there I received a failure: "BroadcastShardOperationFailedException[[index\_test][0] ]; nested: QueryParsingException[[index\_test] No query registered for [query]]; "

Is there some other lightweight manner in which I can get just "hits.total" without the added bloat of each matching doc?

Thanks!

- Pulkit  
--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/a1c1e381-3464-4932-8114-977b2e01c304%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/a1c1e381-3464-4932-8114-977b2e01c304%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/C9753722-16FB-4005-B332-CECE3FED6DF2%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/C9753722-16FB-4005-B332-CECE3FED6DF2%40pilato.fr).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![javanna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/javanna/32/4698_2.png) [@javanna](https://discuss.elastic.co/u/javanna)\
**Post date:** [February 24, 2014, 7:38am UTC](https://discuss.elastic.co/t/count-versus-search-api/15981/3 "2014-02-24T07:38:23Z")

</div>

I guess you are still on 0.90, where the count request is slightly  
different compared to a search request, as it contains the query without it  
being wrapped into the query object:

{  
"term" : {"field":"value"}  
}

instead of

{  
"query" : {  
"term" : {"field":"value"}  
}  
}

Beware that we changed this in 1.0 to have consistency between count api  
and search api.

On Monday, February 24, 2014 4:51:43 AM UTC+1, pulkitsinghal wrote:

> Hello,
> 
> I have a bool query with a filter applied to it, which runs against the  
> \_search endpoint successfully giving "hits.total" but unfortunately it also  
> gives a lot more data than that which I don't need.
> 
> So I thought of running the same query against the \_count endpoint but  
> there I received a  
> failure: "BroadcastShardOperationFailedException[[index\_test][0] ]; nested:  
> QueryParsingException[[index\_test] No query registered for [query]]; "
> 
> Is there some other lightweight manner in which I can get just  
> "hits.total" without the added bloat of each matching doc?
> 
> Thanks!
> 
> - Pulkit

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/6d7827db-af6e-4f5e-a394-bfb09652be7a%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/6d7827db-af6e-4f5e-a394-bfb09652be7a%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![pulkitsinghal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pulkitsinghal/32/802_2.png) [@pulkitsinghal](https://discuss.elastic.co/u/pulkitsinghal)\
**Post date:** [February 24, 2014, 12:30pm UTC](https://discuss.elastic.co/t/count-versus-search-api/15981/4 "2014-02-24T12:30:23Z")

</div>

Hey @David, since Luca had zeroed-in-on the issue, I'll skip providing the  
query this time.

@Luca - Thanks! That was exactly the problem! Another thing that is  
inconsistent right now is that I can use date math against the \_search  
endpoint for filters but not against the \_count endpoint in 0.90:  
"lt" : "now",  
"gte" : "now-1w"  
versus:  
"lt" : "2014-02-24",  
"gte" : "2014-02-17"

- Pulkit  
(646)-535-2357  
Cofounder & CTO, ShoppinPal  
[https://linkedin.com/in/pulkitsinghal](https://linkedin.com/in/pulkitsinghal)  
[https://coderbits.com/pulkitsinghal](https://coderbits.com/pulkitsinghal)

On Mon, Feb 24, 2014 at 1:38 AM, Luca Cavanna [cavannaluca@gmail.com](mailto:cavannaluca@gmail.com) wrote:

> I guess you are still on 0.90, where the count request is slightly  
> different compared to a search request, as it contains the query without it  
> being wrapped into the query object:
> 
> {  
> "term" : {"field":"value"}  
> }
> 
> instead of
> 
> {  
> "query" : {  
> "term" : {"field":"value"}  
> }  
> }
> 
> Beware that we changed this in 1.0 to have consistency between count api  
> and search api.
> 
> On Monday, February 24, 2014 4:51:43 AM UTC+1, pulkitsinghal wrote:
> 
> > Hello,
> > 
> > I have a bool query with a filter applied to it, which runs against the  
> > \_search endpoint successfully giving "hits.total" but unfortunately it also  
> > gives a lot more data than that which I don't need.
> > 
> > So I thought of running the same query against the \_count endpoint but  
> > there I received a failure: "BroadcastShardOperationFailedException[[index\_test][0]  
> > ]; nested: QueryParsingException[[index\_test] No query registered for  
> > [query]]; "
> > 
> > Is there some other lightweight manner in which I can get just  
> > "hits.total" without the added bloat of each matching doc?
> > 
> > Thanks!
> > 
> > - Pulkit
> 
> --  
> 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).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/6d7827db-af6e-4f5e-a394-bfb09652be7a%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/6d7827db-af6e-4f5e-a394-bfb09652be7a%40googlegroups.com)  
> .
> 
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CADA%3DEV807-Us2vVqcf8vbif-1Mxsx4rGtV8nn%3D0KyX\_tWJYLaA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CADA%3DEV807-Us2vVqcf8vbif-1Mxsx4rGtV8nn%3D0KyX_tWJYLaA%40mail.gmail.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, 1:47am UTC](https://discuss.elastic.co/t/count-versus-search-api/15981/5 "2017-07-06T01:47:51Z")

</div>


