# ElasticSearch Count API

**URL:** <https://discuss.elastic.co/t/elasticsearch-count-api/6221>\
**Category:** Elasticsearch\
**Created:** [December 22, 2011, 3:41pm UTC](https://discuss.elastic.co/t/elasticsearch-count-api/6221 "2011-12-22T15:41:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Virgile\_Devaux\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/virgile_devaux_2/32/2139_2.png) [@Virgile\_Devaux\_2](https://discuss.elastic.co/u/Virgile_Devaux_2)\
**Post date:** [December 22, 2011, 3:41pm UTC](https://discuss.elastic.co/t/elasticsearch-count-api/6221/1 "2011-12-22T15:41:34Z")

</div>

in [http://www.elasticsearch.org/guide/reference/api/count.html](http://www.elasticsearch.org/guide/reference/api/count.html) it's  
said that:  
"The query is optional, and when not provided, it will use  
match\_all to count all the docs."  
But if I don't set a query parameter, I get the following error:  
{"error":"No query to execute, not in body, and not bounded to 'q'  
parameter"}%

The gist: [https://gist.github.com/1510709](https://gist.github.com/1510709) illustrates this point.

Is this something that will change soon? If not, what is the best  
(performance) way of requesting a count for all the document in the  
indices/types?

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [December 22, 2011, 5:05pm UTC](https://discuss.elastic.co/t/elasticsearch-count-api/6221/2 "2011-12-22T17:05:51Z")

</div>

On Thu, 2011-12-22 at 07:41 -0800, Virgile Devaux wrote:

> in [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/count.html) it's  
> said that:  
> "The query is optional, and when not provided, it will use  
> match\_all to count all the docs."  
> But if I don't set a query parameter, I get the following error:  
> {"error":"No query to execute, not in body, and not bounded to 'q'  
> parameter"}%

What version of ES are you using? Up until recently, ES did require a  
query. If you've got an older version, then you can do this:

curl -XGET [http://localhost:9200/\_count](http://localhost:9200/_count) -d '{ match\_all: {}}'

clint

---

<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:44am UTC](https://discuss.elastic.co/t/elasticsearch-count-api/6221/3 "2017-07-06T03:44:34Z")

</div>


