# Multiple Facet Searches

**URL:** https://discuss.elastic.co/t/multiple-facet-searches/13043
**Category:** Elasticsearch
**Created:** [August 2, 2013, 2:28pm UTC](https://discuss.elastic.co/t/multiple-facet-searches/13043 "2013-08-02T14:28:11Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![William\_Finn](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/william_finn/32/2301_2.png) [@William\_Finn](https://discuss.elastic.co/u/William_Finn)
#### Post date: [August 2, 2013, 2:28pm UTC](https://discuss.elastic.co/t/multiple-facet-searches/13043/1 "2013-08-02T14:28:11Z")

</div>

Hi,

I am trying to run a search query using multiple facets, and I want the  
facet numbers to update in the same way as the site Zappos does. For  
example, when I search for Nike in the men's shoe section, I get facets for  
Brand and Color.

[https://lh6.googleusercontent.com/-3upIQdUCw7s/UfvBXZ8J9rI/AAAAAAAAJiE/Fv0SYGcfOD8/s1600/Screen+Shot+2013-08-02+at+9.05.44+AM.png](https://lh6.googleusercontent.com/-3upIQdUCw7s/UfvBXZ8J9rI/AAAAAAAAJiE/Fv0SYGcfOD8/s1600/Screen+Shot+2013-08-02+at+9.05.44+AM.png)

When I narrow my search by Brand (by selecting 'Nike'), the numbers within  
the Brand facet do not change, but the numbers within the Color facet  
change to reflect the narrowed search results.

[https://lh3.googleusercontent.com/-PwDqkB4r49M/UfvBiNCP-fI/AAAAAAAAJiM/OK-LHewj4k4/s1600/Screen+Shot+2013-08-02+at+9.07.05+AM.png](https://lh3.googleusercontent.com/-PwDqkB4r49M/UfvBiNCP-fI/AAAAAAAAJiM/OK-LHewj4k4/s1600/Screen+Shot+2013-08-02+at+9.07.05+AM.png)

I can widen my search by selecting 'Nike Action', and still no numbers  
within the Brand facet are updated, but numbers in the Color facet have  
been updated to reflect the additional results.

[https://lh3.googleusercontent.com/-0sBDHJLzwxc/UfvBpbV-X5I/AAAAAAAAJiU/dXU48nPUqXs/s1600/Screen+Shot+2013-08-02+at+9.08.20+AM.png](https://lh3.googleusercontent.com/-0sBDHJLzwxc/UfvBpbV-X5I/AAAAAAAAJiU/dXU48nPUqXs/s1600/Screen+Shot+2013-08-02+at+9.08.20+AM.png)

I can see the same expected results if I select a term within the Color  
facet:

[https://lh5.googleusercontent.com/-eN0havFUmZs/UfvBufhko6I/AAAAAAAAJic/Nf\_\_QYsUr\_c/s1600/Screen+Shot+2013-08-02+at+9.09.32+AM.png](https://lh5.googleusercontent.com/-eN0havFUmZs/UfvBufhko6I/AAAAAAAAJic/Nf__QYsUr_c/s1600/Screen+Shot+2013-08-02+at+9.09.32+AM.png)

I can think of two ways to do this using Elastic Search, and I'm looking  
for any guidance/suggestions as to the best way to implement this.

1. Filtered query using fairly complex facet filters within each facet,  
including global = true flag.

2. Top-level filter (which I understand does not affect the facet results)  
with slightly less complex facet filters within each facet

Which of the two options would perform better? Is there a better option  
that I'm not thinking of? I can add example JSON if it will help explain my  
thoughts.

Thanks!

Bill

PS - Apologies if this hits the group twice. I tried first via email, and  
it didn't seem to work.

--  
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: [August 4, 2013, 2:34pm UTC](https://discuss.elastic.co/t/multiple-facet-searches/13043/2 "2013-08-04T14:34:06Z")

</div>

I would opt for the second suggestion. Your top-level query will have a  
filter, but it should not be a filtered query. With a filtered query, the  
facets will only be run on the resulting documents, but since you want  
every brand, it will not work (unless you use the global flag). With a  
normal query/filter query, the facets will be run on the non-filtered  
results.

The filter used on the query will be used as a facet filter on the color  
facet. The brand facet will have a special filter, which is the one used on  
the query, minus the brand filter clause (presumably a term filter).

Cannot say which performs better, but I would assume the global=true option  
would not be as performant since you have to filter on all documents.

Cheers,

Ivan

On Fri, Aug 2, 2013 at 7:28 AM, William Finn [william.finn@gmail.com](mailto:william.finn@gmail.com) wrote:

> Hi,
> 
> I am trying to run a search query using multiple facets, and I want the  
> facet numbers to update in the same way as the site Zappos does. For  
> example, when I search for Nike in the men's shoe section, I get facets for  
> Brand and Color.
> 
> [https://lh6.googleusercontent.com/-3upIQdUCw7s/UfvBXZ8J9rI/AAAAAAAAJiE/Fv0SYGcfOD8/s1600/Screen+Shot+2013-08-02+at+9.05.44+AM.png](https://lh6.googleusercontent.com/-3upIQdUCw7s/UfvBXZ8J9rI/AAAAAAAAJiE/Fv0SYGcfOD8/s1600/Screen+Shot+2013-08-02+at+9.05.44+AM.png)
> 
> When I narrow my search by Brand (by selecting 'Nike'), the numbers within  
> the Brand facet do not change, but the numbers within the Color facet  
> change to reflect the narrowed search results.
> 
> [https://lh3.googleusercontent.com/-PwDqkB4r49M/UfvBiNCP-fI/AAAAAAAAJiM/OK-LHewj4k4/s1600/Screen+Shot+2013-08-02+at+9.07.05+AM.png](https://lh3.googleusercontent.com/-PwDqkB4r49M/UfvBiNCP-fI/AAAAAAAAJiM/OK-LHewj4k4/s1600/Screen+Shot+2013-08-02+at+9.07.05+AM.png)
> 
> I can widen my search by selecting 'Nike Action', and still no numbers  
> within the Brand facet are updated, but numbers in the Color facet have  
> been updated to reflect the additional results.
> 
> [https://lh3.googleusercontent.com/-0sBDHJLzwxc/UfvBpbV-X5I/AAAAAAAAJiU/dXU48nPUqXs/s1600/Screen+Shot+2013-08-02+at+9.08.20+AM.png](https://lh3.googleusercontent.com/-0sBDHJLzwxc/UfvBpbV-X5I/AAAAAAAAJiU/dXU48nPUqXs/s1600/Screen+Shot+2013-08-02+at+9.08.20+AM.png)
> 
> I can see the same expected results if I select a term within the Color  
> facet:
> 
> [https://lh5.googleusercontent.com/-eN0havFUmZs/UfvBufhko6I/AAAAAAAAJic/Nf\_\_QYsUr\_c/s1600/Screen+Shot+2013-08-02+at+9.09.32+AM.png](https://lh5.googleusercontent.com/-eN0havFUmZs/UfvBufhko6I/AAAAAAAAJic/Nf__QYsUr_c/s1600/Screen+Shot+2013-08-02+at+9.09.32+AM.png)
> 
> I can think of two ways to do this using Elastic Search, and I'm looking  
> for any guidance/suggestions as to the best way to implement this.
> 
> 1. Filtered query using fairly complex facet filters within each facet,  
> including global = true flag.
> 
> 2. Top-level filter (which I understand does not affect the facet results)  
> with slightly less complex facet filters within each facet
> 
> Which of the two options would perform better? Is there a better option  
> that I'm not thinking of? I can add example JSON if it will help explain my  
> thoughts.
> 
> Thanks!
> 
> Bill
> 
> PS - Apologies if this hits the group twice. I tried first via email, and  
> it didn't seem to work.
> 
> --  
> 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:23am UTC](https://discuss.elastic.co/t/multiple-facet-searches/13043/3 "2017-07-06T02:23:06Z")

</div>


