Aggregations without impact of filter in query

Hello

I am using ES 1.5.2, Java API. I am working on implemented filterd/faceted/refine search in our product. Left side filters include countries, state, city etc. I want these values to depend only on keywords or query string and have no impact of filter applied. I will explain this using a usecase:

Let us say we are buying a TV in amazon: (Link: http://www.amazon.com/s/ref=nb_sb_noss/191-1530259-0387204?url=search-alias%3Daps&field-keywords=tv )

I need all values in left side "REFINE BY" section for ALL interactions/filters applied in that block.

Simply put in ES terms, I want my aggregations to have no impact of the query part.

Any help would be awesome.

Thanks
Sri Harsha

You are probably looking for the post filter.

1 Like

Thanks a lot jpountz :slight_smile: Exactly what I was looking for, I got confused with all, global, filters in aggs.

Just a quick question:
Are there any other ways we can achieve this?, I somewhere read that post filters are not fast or so.

Thanks
Sri Harsha

The actual explanation is not that post filters are not fast but that filtered queries are very fast: when you run a filtered query, elasticsearch will leverage the inverted index in order to quickly compute the intersection of your query and your filter. When you have a post filter, elasticsearch will only use the query (which might match many more docs than the intersection) and then check for every document matching the query if it also matches the filter. This is why if you don't have aggregations, then a regular filtered query will be much faster than a query with a post filter.

However in your case, you need to collect all documents that match the query anyway for aggregations, so you don't really have any other option.

Thank you :smile: