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


(Carl Sharma) #1

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.


(Otis Gospodnetić) #2

Hi Chetan,

Not sure if you saw http://www.elasticsearch.org/guide/reference/api/count.html

Otis

Sematext - Hiring ElasticSearch / Solr Devs - http://sematext.com/about/jobs.html

On Jan 18, 12:50 am, Chetan Sharma 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.


(Shay Banon) #3

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> wrote:

Hi Chetan,

Not sure if you saw
http://www.elasticsearch.org/guide/reference/api/count.html

Otis

Sematext - Hiring ElasticSearch / Solr Devs -
http://sematext.com/about/jobs.html

On Jan 18, 12:50 am, Chetan Sharma 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.


(Carl Sharma) #4

Thanks Guys.. Its great help.


(Carl Sharma) #5

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


(Shay Banon) #6

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 wrote:

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


(Carl Sharma) #7

Thanks.

On Fri, Jan 20, 2012 at 8:31 PM, Shay Banon 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 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 )


Exclusive ElggStore: http://www.pluginlotto.com


(Carl Sharma) #8

Thanks alot. This was what I wanted :slight_smile:


(system) #9