# Bool and and/or filter

**URL:** <https://discuss.elastic.co/t/bool-and-and-or-filter/21292>\
**Category:** Elasticsearch\
**Created:** [December 17, 2014, 10:06am UTC](https://discuss.elastic.co/t/bool-and-and-or-filter/21292 "2014-12-17T10:06:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Han\_JU](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/han_ju/32/962_2.png) [@Han\_JU](https://discuss.elastic.co/u/Han_JU)\
**Post date:** [December 17, 2014, 10:06am UTC](https://discuss.elastic.co/t/bool-and-and-or-filter/21292/1 "2014-12-17T10:06:14Z")

</div>

Hi,

We're revising our usage of ElasticSearch.  
Currently we use and/or filter to glue multiple filters together, but after  
some reading on the documentation I wonders if it's better to use bool.

As far as I understand, bool filters uses a bitmap approach, that is  
sub-filters returns bitmaps and an `and` binary operation is applied on all  
partial bitmaps to obtain the result.  
And for and/or query, it's more an iterator approach, a stream of documents  
comes in, pass over all filters and finally filtered document stream comes  
out.

I've read in the `internal filter operation` part, it says that filter  
results are cached in the form of bitmaps. So does it means that bool  
filter can benefit from the cache, while and/or filter cannot?  
In general how do we choose between bool filter and and/or filter?

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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/739206ed-e408-4942-8a25-32f75273a65d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/739206ed-e408-4942-8a25-32f75273a65d%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [December 17, 2014, 10:10am UTC](https://discuss.elastic.co/t/bool-and-and-or-filter/21292/2 "2014-12-17T10:10:29Z")

</div>

You should read this: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/blog/all-about-elasticsearch-filter-bitsets/) [http://www.elasticsearch.org/blog/all-about-elasticsearch-filter-bitsets/](http://www.elasticsearch.org/blog/all-about-elasticsearch-filter-bitsets/)

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr [https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr) | @scrutmydocs [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)

> Le 17 déc. 2014 à 11:06, Han JU [ju.han.felix@gmail.com](mailto:ju.han.felix@gmail.com) a écrit :
> 
> Hi,
> 
> We're revising our usage of Elasticsearch.  
> Currently we use and/or filter to glue multiple filters together, but after some reading on the documentation I wonders if it's better to use bool.
> 
> As far as I understand, bool filters uses a bitmap approach, that is sub-filters returns bitmaps and an `and` binary operation is applied on all partial bitmaps to obtain the result.  
> And for and/or query, it's more an iterator approach, a stream of documents comes in, pass over all filters and finally filtered document stream comes out.
> 
> I've read in the `internal filter operation` part, it says that filter results are cached in the form of bitmaps. So does it means that bool filter can benefit from the cache, while and/or filter cannot?  
> In general how do we choose between bool filter and and/or filter?
> 
> 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) [mailto:elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/739206ed-e408-4942-8a25-32f75273a65d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/739206ed-e408-4942-8a25-32f75273a65d%40googlegroups.com) [https://groups.google.com/d/msgid/elasticsearch/739206ed-e408-4942-8a25-32f75273a65d%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/739206ed-e408-4942-8a25-32f75273a65d%40googlegroups.com?utm_medium=email&utm_source=footer).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout) [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/72A856DD-790D-464F-94B3-EAF53FF7FD59%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/72A856DD-790D-464F-94B3-EAF53FF7FD59%40pilato.fr).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Han\_JU](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/han_ju/32/962_2.png) [@Han\_JU](https://discuss.elastic.co/u/Han_JU)\
**Post date:** [December 17, 2014, 2:45pm UTC](https://discuss.elastic.co/t/bool-and-and-or-filter/21292/3 "2014-12-17T14:45:19Z")

</div>

Oh thanks David ..  
Maybe add some information in the and/or filter documentation page.

在 2014年12月17日星期三UTC+1上午11时10分39秒，David Pilato写道：

> You should read this:  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/blog/all-about-elasticsearch-filter-bitsets/)
> 
> --  
> _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)  
> [http://Elasticsearch.com](http://Elasticsearch.com)_  
> @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr  
> [https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr) | @scrutmydocs  
> [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)
> 
> Le 17 déc. 2014 à 11:06, Han JU \<[ju.han...@gmail.com](mailto:ju.han...@gmail.com) \<javascript:\>\> a  
> écrit :
> 
> Hi,
> 
> We're revising our usage of Elasticsearch.  
> Currently we use and/or filter to glue multiple filters together, but  
> after some reading on the documentation I wonders if it's better to use  
> bool.
> 
> As far as I understand, bool filters uses a bitmap approach, that is  
> sub-filters returns bitmaps and an `and` binary operation is applied on all  
> partial bitmaps to obtain the result.  
> And for and/or query, it's more an iterator approach, a stream of  
> documents comes in, pass over all filters and finally filtered document  
> stream comes out.
> 
> I've read in the `internal filter operation` part, it says that filter  
> results are cached in the form of bitmaps. So does it means that bool  
> filter can benefit from the cache, while and/or filter cannot?  
> In general how do we choose between bool filter and and/or filter?
> 
> 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/739206ed-e408-4942-8a25-32f75273a65d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/739206ed-e408-4942-8a25-32f75273a65d%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/739206ed-e408-4942-8a25-32f75273a65d%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/739206ed-e408-4942-8a25-32f75273a65d%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/6f12b81c-5602-4496-a871-283025eb9c21%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/6f12b81c-5602-4496-a871-283025eb9c21%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [December 17, 2014, 2:49pm UTC](https://discuss.elastic.co/t/bool-and-and-or-filter/21292/4 "2014-12-17T14:49:43Z")

</div>

AFAIK things are subject to change in ES 2.0 and may be only bool will remain.

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

> Le 17 déc. 2014 à 15:45, Han JU [ju.han.felix@gmail.com](mailto:ju.han.felix@gmail.com) a écrit :
> 
> Oh thanks David ..  
> Maybe add some information in the and/or filter documentation page.
> 
> 在 2014年12月17日星期三UTC+1上午11时10分39秒，David Pilato写道：
> 
> > You should read this: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/blog/all-about-elasticsearch-filter-bitsets/)
> > 
> > --  
> > David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
> > @dadoonet | @elasticsearchfr | @scrutmydocs
> > 
> > > Le 17 déc. 2014 à 11:06, Han JU [ju.han...@gmail.com](mailto:ju.han...@gmail.com) a écrit :
> > > 
> > > Hi,
> > > 
> > > We're revising our usage of Elasticsearch.  
> > > Currently we use and/or filter to glue multiple filters together, but after some reading on the documentation I wonders if it's better to use bool.
> > > 
> > > As far as I understand, bool filters uses a bitmap approach, that is sub-filters returns bitmaps and an `and` binary operation is applied on all partial bitmaps to obtain the result.  
> > > And for and/or query, it's more an iterator approach, a stream of documents comes in, pass over all filters and finally filtered document stream comes out.
> > > 
> > > I've read in the `internal filter operation` part, it says that filter results are cached in the form of bitmaps. So does it means that bool filter can benefit from the cache, while and/or filter cannot?  
> > > In general how do we choose between bool filter and and/or filter?
> > > 
> > > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/739206ed-e408-4942-8a25-32f75273a65d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/739206ed-e408-4942-8a25-32f75273a65d%40googlegroups.com).  
> > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> 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).  
> To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/6f12b81c-5602-4496-a871-283025eb9c21%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/6f12b81c-5602-4496-a871-283025eb9c21%40googlegroups.com).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/1B11F351-2542-437E-9DBE-64E2FE701515%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/1B11F351-2542-437E-9DBE-64E2FE701515%40pilato.fr).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 12:43am UTC](https://discuss.elastic.co/t/bool-and-and-or-filter/21292/5 "2017-07-06T00:43:11Z")

</div>


