# Pure boolean query - just return true or false, no result set

**URL:** <https://discuss.elastic.co/t/pure-boolean-query-just-return-true-or-false-no-result-set/12352>\
**Category:** Elasticsearch\
**Created:** [June 11, 2013, 12:44am UTC](https://discuss.elastic.co/t/pure-boolean-query-just-return-true-or-false-no-result-set/12352 "2013-06-11T00:44:25Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Allan\_Johns](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/allan_johns/32/2387_2.png) [@Allan\_Johns](https://discuss.elastic.co/u/Allan_Johns)\
**Post date:** [June 11, 2013, 12:44am UTC](https://discuss.elastic.co/t/pure-boolean-query-just-return-true-or-false-no-result-set/12352/1 "2013-06-11T00:44:25Z")

</div>

I have a case where I need to find out if any documents match a given  
query, but I don't need the result set, or even a count of the result.

What is the most efficient way to do this, and is there room for a new  
feature in ES tailored to this case? I'm currently using the count API, but  
I suspect even that is doing more work than I actually need.

Thanks,  
A

--  
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:** ![mattweber](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mattweber/32/44940_2.png) [@mattweber](https://discuss.elastic.co/u/mattweber)\
**Post date:** [June 11, 2013, 1:40am UTC](https://discuss.elastic.co/t/pure-boolean-query-just-return-true-or-false-no-result-set/12352/2 "2013-06-11T01:40:38Z")

</div>

I don't think there is anything like this for queries. You can do a HEAD  
request for a specific document, but not for searches. I would do the  
query with a size of 0 using the query and fetch search type for the  
fastest execution.

On Mon, Jun 10, 2013 at 5:44 PM, Allan Johns [nerdvegas@gmail.com](mailto:nerdvegas@gmail.com) wrote:

> I have a case where I need to find out if any documents match a given  
> query, but I don't need the result set, or even a count of the result.
> 
> What is the most efficient way to do this, and is there room for a new  
> feature in ES tailored to this case? I'm currently using the count API, but  
> I suspect even that is doing more work than I actually need.
> 
> Thanks,  
> A
> 
> --  
> 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:** ![q42jaap](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/q42jaap/32/2241_2.png) [@q42jaap](https://discuss.elastic.co/u/q42jaap)\
**Post date:** [June 11, 2013, 8:43pm UTC](https://discuss.elastic.co/t/pure-boolean-query-just-return-true-or-false-no-result-set/12352/3 "2013-06-11T20:43:36Z")

</div>

I guess the count API is very efficient for this. Are you running into  
performance problems and if you are, maybe you could give the us insights  
in how your data is structured?  
Whether there could be an even more efficient in Elasticsearch internally,  
I don't doubt that, I only think that this feature will not be high on the  
roadmap.

Do you issue the same query a lot? Or are the query's different? Can you  
possibly use filters to be able to use caches?

Jaap

On Tuesday, June 11, 2013 3:40:38 AM UTC+2, Matt Weber wrote:

> I don't think there is anything like this for queries. You can do a HEAD  
> request for a specific document, but not for searches. I would do the  
> query with a size of 0 using the query and fetch search type for the  
> fastest execution.
> 
> On Mon, Jun 10, 2013 at 5:44 PM, Allan Johns \<[nerd...@gmail.com](mailto:nerd...@gmail.com)\<javascript:\>
> 
> > wrote:
> 
> > I have a case where I need to find out if any documents match a given  
> > query, but I don't need the result set, or even a count of the result.
> > 
> > What is the most efficient way to do this, and is there room for a new  
> > feature in ES tailored to this case? I'm currently using the count API, but  
> > I suspect even that is doing more work than I actually need.
> > 
> > Thanks,  
> > A
> > 
> > --  
> > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > 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:** ![Allan\_Johns](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/allan_johns/32/2387_2.png) [@Allan\_Johns](https://discuss.elastic.co/u/Allan_Johns)\
**Post date:** [June 11, 2013, 11:20pm UTC](https://discuss.elastic.co/t/pure-boolean-query-just-return-true-or-false-no-result-set/12352/4 "2013-06-11T23:20:16Z")

</div>

Hi Jaap,

I'm not running into performance problems - yet - I just have a special  
case where I don't need the result set at all. Also, the query in question  
varies too much, I don't think I can get much benefit from caching.

thx  
A

On Wed, Jun 12, 2013 at 6:43 AM, Jaap Taal [jaap@q42.nl](mailto:jaap@q42.nl) wrote:

> I guess the count API is very efficient for this. Are you running into  
> performance problems and if you are, maybe you could give the us insights  
> in how your data is structured?  
> Whether there could be an even more efficient in Elasticsearch internally,  
> I don't doubt that, I only think that this feature will not be high on the  
> roadmap.
> 
> Do you issue the same query a lot? Or are the query's different? Can you  
> possibly use filters to be able to use caches?
> 
> Jaap
> 
> On Tuesday, June 11, 2013 3:40:38 AM UTC+2, Matt Weber wrote:
> 
> > I don't think there is anything like this for queries. You can do a HEAD  
> > request for a specific document, but not for searches. I would do the  
> > query with a size of 0 using the query and fetch search type for the  
> > fastest execution.
> > 
> > On Mon, Jun 10, 2013 at 5:44 PM, Allan Johns [nerd...@gmail.com](mailto:nerd...@gmail.com) wrote:
> > 
> > > I have a case where I need to find out if any documents match a given  
> > > query, but I don't need the result set, or even a count of the result.
> > > 
> > > What is the most efficient way to do this, and is there room for a new  
> > > feature in ES tailored to this case? I'm currently using the count API, but  
> > > I suspect even that is doing more work than I actually need.
> > > 
> > > Thanks,  
> > > A
> > > 
> > > --  
> > > 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 elasticsearc...@\*\*[googlegroups.com](http://googlegroups.com).
> > > 
> > > For more options, visit [https://groups.google.com/\*\*groups/opt\_out](https://groups.google.com/**groups/opt_out)[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).

--  
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:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [June 12, 2013, 5:49pm UTC](https://discuss.elastic.co/t/pure-boolean-query-just-return-true-or-false-no-result-set/12352/5 "2013-06-12T17:49:37Z")

</div>

I would just use a count query. The heavy lifting of querying the index is  
done already. Condensing the returned result set to true or false will  
hardly save you anything over executing a count query.

--  
Ivan

On Tue, Jun 11, 2013 at 4:20 PM, Allan Johns [nerdvegas@gmail.com](mailto:nerdvegas@gmail.com) wrote:

> Hi Jaap,
> 
> I'm not running into performance problems - yet - I just have a special  
> case where I don't need the result set at all. Also, the query in question  
> varies too much, I don't think I can get much benefit from caching.
> 
> thx  
> A
> 
> On Wed, Jun 12, 2013 at 6:43 AM, Jaap Taal [jaap@q42.nl](mailto:jaap@q42.nl) wrote:
> 
> > I guess the count API is very efficient for this. Are you running into  
> > performance problems and if you are, maybe you could give the us insights  
> > in how your data is structured?  
> > Whether there could be an even more efficient in Elasticsearch  
> > internally, I don't doubt that, I only think that this feature will not be  
> > high on the roadmap.
> > 
> > Do you issue the same query a lot? Or are the query's different? Can you  
> > possibly use filters to be able to use caches?
> > 
> > Jaap
> > 
> > On Tuesday, June 11, 2013 3:40:38 AM UTC+2, Matt Weber wrote:
> > 
> > > I don't think there is anything like this for queries. You can do a  
> > > HEAD request for a specific document, but not for searches. I would do the  
> > > query with a size of 0 using the query and fetch search type for the  
> > > fastest execution.
> > > 
> > > On Mon, Jun 10, 2013 at 5:44 PM, Allan Johns [nerd...@gmail.com](mailto:nerd...@gmail.com) wrote:
> > > 
> > > > I have a case where I need to find out if any documents match a given  
> > > > query, but I don't need the result set, or even a count of the result.
> > > > 
> > > > What is the most efficient way to do this, and is there room for a new  
> > > > feature in ES tailored to this case? I'm currently using the count API, but  
> > > > I suspect even that is doing more work than I actually need.
> > > > 
> > > > Thanks,  
> > > > A
> > > > 
> > > > --  
> > > > 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 elasticsearc...@\*\*[googlegroups.com](http://googlegroups.com).
> > > > 
> > > > For more options, visit [https://groups.google.com/\*\*groups/opt\_out](https://groups.google.com/**groups/opt_out)[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).
> 
> --  
> 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:** ![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:31am UTC](https://discuss.elastic.co/t/pure-boolean-query-just-return-true-or-false-no-result-set/12352/6 "2017-07-06T02:31:31Z")

</div>


