# Usefullness of count before search?

**URL:** <https://discuss.elastic.co/t/usefullness-of-count-before-search/11743>\
**Category:** Elasticsearch\
**Created:** [April 30, 2013, 7:12am UTC](https://discuss.elastic.co/t/usefullness-of-count-before-search/11743 "2013-04-30T07:12:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![DH1](https://avatars.discourse-cdn.com/v4/letter/d/65b543/32.png) [@DH1](https://discuss.elastic.co/u/DH1)\
**Post date:** [April 30, 2013, 7:12am UTC](https://discuss.elastic.co/t/usefullness-of-count-before-search/11743/1 "2013-04-30T07:12:49Z")

</div>

Hi, everyone.

I was looking at the application we're developping here, using ES, and I  
was wondering..

Right now, when we wand to issue a search, we start by making a count, only  
issuing the search if the count is \> 0.  
We did this thinking that a search being somewhat heavier than a count, we  
would avoid unecessary searches and gain overall performances (we'll have  
quite the number of users).  
So, my question :  
Is a search that brings back zero results heavier than a count?

and the corollary, of course .. is what we are doing usefull?

Thanks.

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![radu\_gheorghe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/radu_gheorghe/32/556_2.png) [@radu\_gheorghe](https://discuss.elastic.co/u/radu_gheorghe)\
**Post date:** [April 30, 2013, 5:54pm UTC](https://discuss.elastic.co/t/usefullness-of-count-before-search/11743/2 "2013-04-30T17:54:52Z")

</div>

Hello,

Just to be clear: you're talking about the Count  
API[http://www.elasticsearch.org/guide/reference/api/count/](http://www.elasticsearch.org/guide/reference/api/count/)? If  
yes, I wouldn't bother counting before search. Last time I've used it ES  
was at 0.19 and I didn't notice any significant performance difference  
between counting and searching, but maybe things have changed.

## Best regards, Radu

[http://sematext.com/](http://sematext.com/) -- Elasticsearch -- Solr -- Lucene

On Tue, Apr 30, 2013 at 10:12 AM, DH [ciddp195@gmail.com](mailto:ciddp195@gmail.com) wrote:

> Hi, everyone.
> 
> I was looking at the application we're developping here, using ES, and I  
> was wondering..
> 
> Right now, when we wand to issue a search, we start by making a count,  
> only issuing the search if the count is \> 0.  
> We did this thinking that a search being somewhat heavier than a count, we  
> would avoid unecessary searches and gain overall performances (we'll have  
> quite the number of users).  
> So, my question :  
> Is a search that brings back zero results heavier than a count?
> 
> and the corollary, of course .. is what we are doing usefull?
> 
> Thanks.
> 
> --  
> 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).  
> 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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![DH1](https://avatars.discourse-cdn.com/v4/letter/d/65b543/32.png) [@DH1](https://discuss.elastic.co/u/DH1)\
**Post date:** [May 2, 2013, 7:53am UTC](https://discuss.elastic.co/t/usefullness-of-count-before-search/11743/3 "2013-05-02T07:53:42Z")

</div>

Indeed, that's what I was talking about.

Thank you for your answer !

Le mardi 30 avril 2013 09:12:49 UTC+2, DH a écrit :

> Hi, everyone.
> 
> I was looking at the application we're developping here, using ES, and I  
> was wondering..
> 
> Right now, when we wand to issue a search, we start by making a count,  
> only issuing the search if the count is \> 0.  
> We did this thinking that a search being somewhat heavier than a count, we  
> would avoid unecessary searches and gain overall performances (we'll have  
> quite the number of users).  
> So, my question :  
> Is a search that brings back zero results heavier than a count?
> 
> and the corollary, of course .. is what we are doing usefull?
> 
> Thanks.

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![David\_G\_Ortega](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/david_g_ortega/32/46359_2.png) [@David\_G\_Ortega](https://discuss.elastic.co/u/David_G_Ortega)\
**Post date:** [May 4, 2013, 9:49am UTC](https://discuss.elastic.co/t/usefullness-of-count-before-search/11743/4 "2013-05-04T09:49:19Z")

</div>

The mission of count as far I understand if for UI that needs to know  
exactly how much docs match your search. Count reduces time of response  
just because it has not to process the doc to create the json, reduces  
network just becuse it does not send the docs back. Also has to be faster  
to come back since has less packets to send.

If you stress both you will note the diff between them. But if you are  
displaying the results directly makes no sense to use one before the other.

David

El martes, 30 de abril de 2013 09:12:49 UTC+2, DH escribió:

> Hi, everyone.
> 
> I was looking at the application we're developping here, using ES, and I  
> was wondering..
> 
> Right now, when we wand to issue a search, we start by making a count,  
> only issuing the search if the count is \> 0.  
> We did this thinking that a search being somewhat heavier than a count, we  
> would avoid unecessary searches and gain overall performances (we'll have  
> quite the number of users).  
> So, my question :  
> Is a search that brings back zero results heavier than a count?
> 
> and the corollary, of course .. is what we are doing usefull?
> 
> Thanks.

--  
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).  
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, 2:38am UTC](https://discuss.elastic.co/t/usefullness-of-count-before-search/11743/5 "2017-07-06T02:38:19Z")

</div>


