# Performance of multiple facets with query filters

**URL:** https://discuss.elastic.co/t/performance-of-multiple-facets-with-query-filters/4725
**Category:** Elasticsearch
**Created:** [June 28, 2011, 11:33am UTC](https://discuss.elastic.co/t/performance-of-multiple-facets-with-query-filters/4725 "2011-06-28T11:33:11Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Nicolas\_Fouche](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nicolas_fouche/32/1849_2.png) [@Nicolas\_Fouche](https://discuss.elastic.co/u/Nicolas_Fouche)
#### Post date: [June 28, 2011, 11:33am UTC](https://discuss.elastic.co/t/performance-of-multiple-facets-with-query-filters/4725/1 "2011-06-28T11:33:11Z")

</div>

Hi,  
Is it faster to make one query with filters and Y facets, instead of  
making Y queries with filters and one facet ?  
ElasticSearch will iterate on all filtered documents, and apply the  
facet algorithms on each of them ? I guess it won't reiterate on all  
filtered documents for each facet ? Seems obvious, but I just need to  
be 100% sure.  
And what happens if the facets have filters ? Do ES merge the query  
and facet filters and make one query ? So it would need to do that for  
each facets ?  
Thanks.

---

<div class="post-metadata">

### Author: ![Chris\_Berkhout](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chris_berkhout/32/3058_2.png) [@Chris\_Berkhout](https://discuss.elastic.co/u/Chris_Berkhout)
#### Post date: [June 28, 2011, 1:08pm UTC](https://discuss.elastic.co/t/performance-of-multiple-facets-with-query-filters/4725/2 "2011-06-28T13:08:27Z")

</div>

I'd imagine that the only way to be 100% sure is to try it 🙂

If you're not yet at the point where you have data to run it on, then  
you may well be optimising prematurely. It could be fast enough either  
way.

Still, I agree that it would be interesting to know more about how the  
algorithms work (unfortunately I don't know either).

Cheers,  
Chris

On Tue, Jun 28, 2011 at 7:33 PM, Nicolas Fouché  
[nicolas.fouche@gmail.com](mailto:nicolas.fouche@gmail.com) wrote:

> Hi,  
> Is it faster to make one query with filters and Y facets, instead of  
> making Y queries with filters and one facet ?  
> Elasticsearch will iterate on all filtered documents, and apply the  
> facet algorithms on each of them ? I guess it won't reiterate on all  
> filtered documents for each facet ? Seems obvious, but I just need to  
> be 100% sure.  
> And what happens if the facets have filters ? Do ES merge the query  
> and facet filters and make one query ? So it would need to do that for  
> each facets ?  
> Thanks.

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [June 28, 2011, 7:44pm UTC](https://discuss.elastic.co/t/performance-of-multiple-facets-with-query-filters/4725/3 "2011-06-28T19:44:32Z")

</div>

Hi,

Facets are calculated as a one pass on the query (putting aside global facets here), even if they have facet filters (which just filter out docs from the facet calculation).

-shay.banon

On Tuesday, June 28, 2011 at 4:08 PM, Chris Berkhout wrote:

> I'd imagine that the only way to be 100% sure is to try it 🙂
> 
> If you're not yet at the point where you have data to run it on, then  
> you may well be optimising prematurely. It could be fast enough either  
> way.
> 
> Still, I agree that it would be interesting to know more about how the  
> algorithms work (unfortunately I don't know either).
> 
> Cheers,  
> Chris
> 
> On Tue, Jun 28, 2011 at 7:33 PM, Nicolas Fouché  
> \<[nicolas.fouche@gmail.com](mailto:nicolas.fouche@gmail.com) ([mailto:nicolas.fouche@gmail.com](mailto:nicolas.fouche@gmail.com))\> wrote:
> 
> > Hi,  
> > Is it faster to make one query with filters and Y facets, instead of  
> > making Y queries with filters and one facet ?  
> > Elasticsearch will iterate on all filtered documents, and apply the  
> > facet algorithms on each of them ? I guess it won't reiterate on all  
> > filtered documents for each facet ? Seems obvious, but I just need to  
> > be 100% sure.  
> > And what happens if the facets have filters ? Do ES merge the query  
> > and facet filters and make one query ? So it would need to do that for  
> > each facets ?  
> > Thanks.

---

<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, 4:02am UTC](https://discuss.elastic.co/t/performance-of-multiple-facets-with-query-filters/4725/4 "2017-07-06T04:02:22Z")

</div>


