# How much resource consuming is to get count only from ES ? What are the ways to just count the total documents?

**URL:** <https://discuss.elastic.co/t/how-much-resource-consuming-is-to-get-count-only-from-es-what-are-the-ways-to-just-count-the-total-documents/6423>\
**Category:** Elasticsearch\
**Created:** [January 18, 2012, 5:50am UTC](https://discuss.elastic.co/t/how-much-resource-consuming-is-to-get-count-only-from-es-what-are-the-ways-to-just-count-the-total-documents/6423 "2012-01-18T05:50:31Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Carl\_Sharma](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carl_sharma/32/2767_2.png) [@Carl\_Sharma](https://discuss.elastic.co/u/Carl_Sharma)\
**Post date:** [January 18, 2012, 5:50am UTC](https://discuss.elastic.co/t/how-much-resource-consuming-is-to-get-count-only-from-es-what-are-the-ways-to-just-count-the-total-documents/6423/1 "2012-01-18T05:50:31Z")

</div>

I have around 2 million documents in my Index currently. Now I have some  
pages where i have to show the statistics of the content. I just want the  
total counts of the documents. But I have to use the complex filters, so  
that i can count only the required documents. Mostly I'm using the "bool"  
and "and" in my queries.

I think I can just send limit : 0 , to fetch the documents, and get the  
total count from the "total hits", but I am not sure will it be fast or is  
there any other way to just count the total documents.

---

<div class="post-metadata">

**Author:** ![otisg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/otisg/32/492_2.png) [@otisg](https://discuss.elastic.co/u/otisg)\
**Post date:** [January 18, 2012, 5:56am UTC](https://discuss.elastic.co/t/how-much-resource-consuming-is-to-get-count-only-from-es-what-are-the-ways-to-just-count-the-total-documents/6423/2 "2012-01-18T05:56:29Z")

</div>

Hi Chetan,

Not sure if you saw [Elastic — The Search AI Company | Elastic](http://www.elasticsearch.org/guide/reference/api/count.html)

## Otis

Sematext - Hiring Elasticsearch / Solr Devs - [Jobs](http://sematext.com/about/jobs.html)

On Jan 18, 12:50 am, Chetan Sharma [c...@izap.in](mailto:c...@izap.in) wrote:

> I have around 2 million documents in my Index currently. Now I have some  
> pages where i have to show the statistics of the content. I just want the  
> total counts of the documents. But I have to use the complex filters, so  
> that i can count only the required documents. Mostly I'm using the "bool"  
> and "and" in my queries.
> 
> I think I can just send limit : 0 , to fetch the documents, and get the  
> total count from the "total hits", but I am not sure will it be fast or is  
> there any other way to just count the total documents.

---

<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 18, 2012, 9:08pm UTC](https://discuss.elastic.co/t/how-much-resource-consuming-is-to-get-count-only-from-es-what-are-the-ways-to-just-count-the-total-documents/6423/3 "2012-01-18T21:08:50Z")

</div>

Another option is to set search\_type in the search request to count. The  
benefit there is that you can also get facets for example.

On Wed, Jan 18, 2012 at 7:56 AM, Otis Gospodnetic \<  
[otis.gospodnetic@gmail.com](mailto:otis.gospodnetic@gmail.com)\> wrote:

> Hi Chetan,
> 
> Not sure if you saw  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/count.html)
> 
> ## Otis
> 
> Sematext - Hiring Elasticsearch / Solr Devs -  
> [Jobs - Sematext](http://sematext.com/about/jobs.html)
> 
> On Jan 18, 12:50 am, Chetan Sharma [c...@izap.in](mailto:c...@izap.in) wrote:
> 
> > I have around 2 million documents in my Index currently. Now I have some  
> > pages where i have to show the statistics of the content. I just want the  
> > total counts of the documents. But I have to use the complex filters, so  
> > that i can count only the required documents. Mostly I'm using the "bool"  
> > and "and" in my queries.
> > 
> > I think I can just send limit : 0 , to fetch the documents, and get the  
> > total count from the "total hits", but I am not sure will it be fast or  
> > is  
> > there any other way to just count the total documents.

---

<div class="post-metadata">

**Author:** ![Carl\_Sharma](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carl_sharma/32/2767_2.png) [@Carl\_Sharma](https://discuss.elastic.co/u/Carl_Sharma)\
**Post date:** [January 20, 2012, 12:51pm UTC](https://discuss.elastic.co/t/how-much-resource-consuming-is-to-get-count-only-from-es-what-are-the-ways-to-just-count-the-total-documents/6423/4 "2012-01-20T12:51:20Z")

</div>

Thanks Guys.. Its great help.

---

<div class="post-metadata">

**Author:** ![Carl\_Sharma](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carl_sharma/32/2767_2.png) [@Carl\_Sharma](https://discuss.elastic.co/u/Carl_Sharma)\
**Post date:** [January 20, 2012, 12:53pm UTC](https://discuss.elastic.co/t/how-much-resource-consuming-is-to-get-count-only-from-es-what-are-the-ways-to-just-count-the-total-documents/6423/5 "2012-01-20T12:53:39Z")

</div>

Just one more question. Will it take the same time as query and fetch the  
document, or it is faster ?

---

<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 20, 2012, 3:01pm UTC](https://discuss.elastic.co/t/how-much-resource-consuming-is-to-get-count-only-from-es-what-are-the-ways-to-just-count-the-total-documents/6423/6 "2012-01-20T15:01:22Z")

</div>

You mean search\_type set to count? If so, it will be faster, since you  
don't need to bring back any hits back, even if you set size to 0,  
search\_type set to count will be faster.

On Fri, Jan 20, 2012 at 2:53 PM, Chetan Sharma [carl@izap.in](mailto:carl@izap.in) wrote:

> Just one more question. Will it take the same time as query and fetch the  
> document, or it is faster ?

---

<div class="post-metadata">

**Author:** ![Carl\_Sharma](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carl_sharma/32/2767_2.png) [@Carl\_Sharma](https://discuss.elastic.co/u/Carl_Sharma)\
**Post date:** [January 20, 2012, 3:07pm UTC](https://discuss.elastic.co/t/how-much-resource-consuming-is-to-get-count-only-from-es-what-are-the-ways-to-just-count-the-total-documents/6423/7 "2012-01-20T15:07:16Z")

</div>

Thanks.

On Fri, Jan 20, 2012 at 8:31 PM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:

> You mean search\_type set to count? If so, it will be faster, since you  
> don't need to bring back any hits back, even if you set size to 0,  
> search\_type set to count will be faster.
> 
> On Fri, Jan 20, 2012 at 2:53 PM, Chetan Sharma [carl@izap.in](mailto:carl@izap.in) wrote:
> 
> > Just one more question. Will it take the same time as query and fetch the  
> > document, or it is faster ?

## --

Your Sincerely,  
Chetan Sharma iZAPTeam ( Social Network Promoter )  
[http://www.izap.in](http://www.izap.in)  
Exclusive ElggStore: [http://www.pluginlotto.com](http://www.pluginlotto.com)

---

<div class="post-metadata">

**Author:** ![Carl\_Sharma](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carl_sharma/32/2767_2.png) [@Carl\_Sharma](https://discuss.elastic.co/u/Carl_Sharma)\
**Post date:** [January 20, 2012, 3:08pm UTC](https://discuss.elastic.co/t/how-much-resource-consuming-is-to-get-count-only-from-es-what-are-the-ways-to-just-count-the-total-documents/6423/8 "2012-01-20T15:08:38Z")

</div>

Thanks alot. This was what I wanted 🙂

---

<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:41am UTC](https://discuss.elastic.co/t/how-much-resource-consuming-is-to-get-count-only-from-es-what-are-the-ways-to-just-count-the-total-documents/6423/9 "2017-07-06T03:41:59Z")

</div>


