# Best practice for getting the total count of a type?

**URL:** https://discuss.elastic.co/t/best-practice-for-getting-the-total-count-of-a-type/4886
**Category:** Elasticsearch
**Created:** [July 18, 2011, 7:46pm UTC](https://discuss.elastic.co/t/best-practice-for-getting-the-total-count-of-a-type/4886 "2011-07-18T19:46:46Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Joel\_Abrahamsson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joel_abrahamsson/32/1924_2.png) [@Joel\_Abrahamsson](https://discuss.elastic.co/u/Joel_Abrahamsson)
#### Post date: [July 18, 2011, 7:46pm UTC](https://discuss.elastic.co/t/best-practice-for-getting-the-total-count-of-a-type/4886/1 "2011-07-18T19:46:46Z")

</div>

I'm trying to get the total count for all documents of a specific  
type. My first idea was to just use the \_count API without specifying  
a query:

[http://localhost](http://localhost).:9200/myindex/BlogPost/\_count

But that fails ({"error":"No query to execute, not in body, and not  
bounded to 'q' parameter"}).

What's the best way to get the count? Doing a query using the \_count  
API?  
[http://localhost](http://localhost).:9200/myindex/BlogPost/\_count?q=\*

Or using the \_search API with no query specifying the search type?  
[http://localhost](http://localhost).:9200/myindex/BlogPost/\_search?search\_type=count

Thanks in advance!

---

<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: [July 18, 2011, 8:01pm UTC](https://discuss.elastic.co/t/best-practice-for-getting-the-total-count-of-a-type/4886/2 "2011-07-18T20:01:24Z")

</div>

Hiya

> Or using the \_search API with no query specifying the search type?  
> [http://localhost:9200/myindex/BlogPost/\_search?search\_type=count](http://localhost:9200/myindex/BlogPost/_search?search_type=count)

This is just fine, otherwise:

curl [http://localhost:9200/myindex/BlogPost/\_count](http://localhost:9200/myindex/BlogPost/_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, 4:00am UTC](https://discuss.elastic.co/t/best-practice-for-getting-the-total-count-of-a-type/4886/3 "2017-07-06T04:00:14Z")

</div>


