# Facet Filter Confusion

**URL:** <https://discuss.elastic.co/t/facet-filter-confusion/10299>\
**Category:** Elasticsearch\
**Created:** [January 10, 2013, 5:21pm UTC](https://discuss.elastic.co/t/facet-filter-confusion/10299 "2013-01-10T17:21:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karussell\_2](https://avatars.discourse-cdn.com/v4/letter/k/54ee81/32.png) [@Karussell\_2](https://discuss.elastic.co/u/Karussell_2)\
**Post date:** [January 10, 2013, 5:21pm UTC](https://discuss.elastic.co/t/facet-filter-confusion/10299/1 "2013-01-10T17:21:13Z")

</div>

Hi,

I just want to apply a filter to the query AND to the facets. When I do:

{"query":{"query\_string":{"query":"userinput someField:someValue"}}

- several facets!  
}

this works and is fast!

But I hoped to make it even faster when doing a filtered query which could  
be better cached (!?). So I tried:

{"query":{  
"filtered": {  
"query":{"query\_string": {"query":"userinput"}},  
"filter":{ "term":{"someField":"someValue"}}  
}}

- several facets!  
}

which is at least 10 times slower on my machine\*\* for my index.  
Is it because the filtered part will be called after the facets have been  
executed?  
bigdesk shows enough free RAM

I think I could probably put the filter into _every_ facet via facet\_filter to  
make it cached and fast,  
but is it really that complicated?

Regards,  
Peter.

\*\* using jdk1.6.0\_26 on ubuntu with elasticsearch 0.19.8

--

---

<div class="post-metadata">

**Author:** ![Karussell\_2](https://avatars.discourse-cdn.com/v4/letter/k/54ee81/32.png) [@Karussell\_2](https://discuss.elastic.co/u/Karussell_2)\
**Post date:** [February 14, 2013, 2:52pm UTC](https://discuss.elastic.co/t/facet-filter-confusion/10299/2 "2013-02-14T14:52:40Z")

</div>

Hey,

forgot to post the solution here. First, the provided information was not  
sufficient, sorry.  
We had a combined "and" filter which was causing the slow response.  
(A simple term filter is still 2 times faster then the query\_string  
equivalent)

But the thing with the "and" filter was still strange. And we fixed it. We  
just replaced the "and" with a "bool" filter (must). Now 3 times faster!

Why are they so different?

Regards,  
Peter.

On Thursday, January 10, 2013 6:21:13 PM UTC+1, Karussell wrote:

> Hi,
> 
> I just want to apply a filter to the query AND to the facets. When I do:
> 
> {"query":{"query\_string":{"query":"userinput someField:someValue"}}
> 
> - several facets!  
> }
> 
> this works and is fast!
> 
> But I hoped to make it even faster when doing a filtered query which could  
> be better cached (!?). So I tried:
> 
> {"query":{  
> "filtered": {  
> "query":{"query\_string": {"query":"userinput"}},  
> "filter":{ "term":{"someField":"someValue"}}  
> }}
> 
> - several facets!  
> }
> 
> which is at least 10 times slower on my machine\*\* for my index.  
> Is it because the filtered part will be called after the facets have been  
> executed?  
> bigdesk shows enough free RAM
> 
> I think I could probably put the filter into _every_ facet via facet\_filter  
> to make it cached and fast,  
> but is it really that complicated?
> 
> Regards,  
> Peter.
> 
> \*\* using jdk1.6.0\_26 on ubuntu with elasticsearch 0.19.8

--  
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:** [February 14, 2013, 5:21pm UTC](https://discuss.elastic.co/t/facet-filter-confusion/10299/3 "2013-02-14T17:21:18Z")

</div>

The boolean filter can use the cached term bitsets and the and/or/not  
filters don't.

On Thu, Feb 14, 2013 at 6:52 AM, Karussell [tableyourtime@gmail.com](mailto:tableyourtime@gmail.com) wrote:

> Hey,
> 
> forgot to post the solution here. First, the provided information was not  
> sufficient, sorry.  
> We had a combined "and" filter which was causing the slow response.  
> (A simple term filter is still 2 times faster then the query\_string  
> equivalent)
> 
> But the thing with the "and" filter was still strange. And we fixed it. We  
> just replaced the "and" with a "bool" filter (must). Now 3 times faster!
> 
> Why are they so different?
> 
> Regards,  
> Peter.
> 
> On Thursday, January 10, 2013 6:21:13 PM UTC+1, Karussell wrote:
> 
> > Hi,
> > 
> > I just want to apply a filter to the query AND to the facets. When I do:
> > 
> > {"query":{"query\_string":{"query":"userinput someField:someValue"}}
> > 
> > - several facets!  
> > }
> > 
> > this works and is fast!
> > 
> > But I hoped to make it even faster when doing a filtered query which could  
> > be better cached (!?). So I tried:
> > 
> > {"query":{  
> > "filtered": {  
> > "query":{"query\_string": {"query":"userinput"}},  
> > "filter":{ "term":{"someField":"someValue"}}  
> > }}
> > 
> > - several facets!  
> > }
> > 
> > which is at least 10 times slower on my machine\*\* for my index.  
> > Is it because the filtered part will be called after the facets have been  
> > executed?  
> > bigdesk shows enough free RAM
> > 
> > I think I could probably put the filter into every facet via facet\_filter  
> > to make it cached and fast,  
> > but is it really that complicated?
> > 
> > Regards,  
> > Peter.
> > 
> > \*\* using jdk1.6.0\_26 on ubuntu with elasticsearch 0.19.8
> 
> --  
> 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:** ![Karussell\_2](https://avatars.discourse-cdn.com/v4/letter/k/54ee81/32.png) [@Karussell\_2](https://discuss.elastic.co/u/Karussell_2)\
**Post date:** [February 18, 2013, 11:34am UTC](https://discuss.elastic.co/t/facet-filter-confusion/10299/4 "2013-02-18T11:34:20Z")

</div>

Hi Matt,

thanks! But is there an advantage of the and/or/not filters?

Regards,  
Peter.

On Thursday, February 14, 2013 6:21:18 PM UTC+1, Matt Weber wrote:

> The boolean filter can use the cached term bitsets and the and/or/not  
> filters don't.
> 
> On Thu, Feb 14, 2013 at 6:52 AM, Karussell \<[tabley...@gmail.com](mailto:tabley...@gmail.com)\<javascript:\>\>  
> wrote:
> 
> > Hey,
> > 
> > forgot to post the solution here. First, the provided information was  
> > not  
> > sufficient, sorry.  
> > We had a combined "and" filter which was causing the slow response.  
> > (A simple term filter is still 2 times faster then the query\_string  
> > equivalent)
> > 
> > But the thing with the "and" filter was still strange. And we fixed it.  
> > We  
> > just replaced the "and" with a "bool" filter (must). Now 3 times faster!
> > 
> > Why are they so different?
> > 
> > Regards,  
> > Peter.
> > 
> > On Thursday, January 10, 2013 6:21:13 PM UTC+1, Karussell wrote:
> > 
> > > Hi,
> > > 
> > > I just want to apply a filter to the query AND to the facets. When I  
> > > do:
> > > 
> > > {"query":{"query\_string":{"query":"userinput someField:someValue"}}
> > > 
> > > - several facets!  
> > > }
> > > 
> > > this works and is fast!
> > > 
> > > But I hoped to make it even faster when doing a filtered query which  
> > > could  
> > > be better cached (!?). So I tried:
> > > 
> > > {"query":{  
> > > "filtered": {  
> > > "query":{"query\_string": {"query":"userinput"}},  
> > > "filter":{ "term":{"someField":"someValue"}}  
> > > }}
> > > 
> > > - several facets!  
> > > }
> > > 
> > > which is at least 10 times slower on my machine\*\* for my index.  
> > > Is it because the filtered part will be called after the facets have  
> > > been  
> > > executed?  
> > > bigdesk shows enough free RAM
> > > 
> > > I think I could probably put the filter into every facet via  
> > > facet\_filter  
> > > to make it cached and fast,  
> > > but is it really that complicated?
> > > 
> > > Regards,  
> > > Peter.
> > > 
> > > \*\* using jdk1.6.0\_26 on ubuntu with elasticsearch 0.19.8
> > 
> > --  
> > 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:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [February 21, 2013, 1:35pm UTC](https://discuss.elastic.co/t/facet-filter-confusion/10299/5 "2013-02-21T13:35:06Z")

</div>

Hi Peter

> thanks! But is there an advantage of the and/or/not filters?

and/or process doc-by-doc, so they are useful for filters which don't  
produce bitsets, especially if they are also heavy filters. For  
instance, if you have a geo-distance filter, put it as the last filter  
in an and|or clause

clint

--  
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:50am UTC](https://discuss.elastic.co/t/facet-filter-confusion/10299/6 "2017-07-06T02:50:21Z")

</div>


