# Compute diff between global and filtered facet filter values

**URL:** <https://discuss.elastic.co/t/compute-diff-between-global-and-filtered-facet-filter-values/7356>\
**Category:** Elasticsearch\
**Created:** [April 16, 2012, 5:41pm UTC](https://discuss.elastic.co/t/compute-diff-between-global-and-filtered-facet-filter-values/7356 "2012-04-16T17:41:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![my3sons](https://avatars.discourse-cdn.com/v4/letter/m/e274bd/32.png) [@my3sons](https://discuss.elastic.co/u/my3sons)\
**Post date:** [April 16, 2012, 5:41pm UTC](https://discuss.elastic.co/t/compute-diff-between-global-and-filtered-facet-filter-values/7356/1 "2012-04-16T17:41:10Z")

</div>

Hello,

I really like the flexibility offered through ElasticSearch with respect to  
Facets (i.e. choose to have facet filter values bound or not bound to  
query). As with most ecommerce sites, we are initially returning "globally"  
selected facets, and then as the user navigates via those facets, we  
continue to show the "globally" selected facet filter values and do not  
bind them to the filtered query, so that the customer can quickly and  
easily navigate many different directions. However, what we would like to  
do now is "grey out/disable" those facet filter values, which are no longer  
reachable given the filtering the user has chosen. For example, if the  
customer has clicked on a specific brand facet filter value, and that facet  
click has removed some price range facet filters from contention, then we  
would like to disable those selections.

I know we could implement some request/session logic to maintain collection  
of initially provided facet filter values and then invoke "filtered"  
queries to bind facets to the query and then do a compare between the two  
to determine what was eliminated and disable accordingly, but I first  
wanted to check with the group here to see if there is a more elegant  
solution using ElasticSearch that others may have implemented to do this.

Thanks!

---

<div class="post-metadata">

**Author:** ![Jan\_Fiedler](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jan_fiedler/32/2518_2.png) [@Jan\_Fiedler](https://discuss.elastic.co/u/Jan_Fiedler)\
**Post date:** [April 17, 2012, 12:02pm UTC](https://discuss.elastic.co/t/compute-diff-between-global-and-filtered-facet-filter-values/7356/2 "2012-04-17T12:02:51Z")

</div>

I had a similar requirement a while back and experimented with  
ElasticSearch global facets to solve it. I ended up creating two facets per  
faceted attribute and merging the calculated facet values. I used the  
global facet to basically give me the total value range with 0 hit count.  
When merging I basically overwrite the 0 hit count from the global facet  
with whatever the actual filtered facet provided. Values not part of the  
filtered facet obviously remained with a 0 hit count which can be used  
during rendering to disable options. Not sure this is the most elegant way  
but it was the only one I found back then.

---

<div class="post-metadata">

**Author:** ![my3sons](https://avatars.discourse-cdn.com/v4/letter/m/e274bd/32.png) [@my3sons](https://discuss.elastic.co/u/my3sons)\
**Post date:** [April 17, 2012, 1:58pm UTC](https://discuss.elastic.co/t/compute-diff-between-global-and-filtered-facet-filter-values/7356/3 "2012-04-17T13:58:33Z")

</div>

Thanks Jan! Interesting approach and I will give it a try...

On Tuesday, April 17, 2012 7:02:51 AM UTC-5, Jan Fiedler wrote:

> I had a similar requirement a while back and experimented with  
> Elasticsearch global facets to solve it. I ended up creating two facets per  
> faceted attribute and merging the calculated facet values. I used the  
> global facet to basically give me the total value range with 0 hit count.  
> When merging I basically overwrite the 0 hit count from the global facet  
> with whatever the actual filtered facet provided. Values not part of the  
> filtered facet obviously remained with a 0 hit count which can be used  
> during rendering to disable options. Not sure this is the most elegant way  
> but it was the only one I found back then.

---

<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, 3:32am UTC](https://discuss.elastic.co/t/compute-diff-between-global-and-filtered-facet-filter-values/7356/4 "2017-07-06T03:32:13Z")

</div>


