# How to implement feature: "change in #results after clicking a facet"

**URL:** <https://discuss.elastic.co/t/how-to-implement-feature-change-in-results-after-clicking-a-facet/12877>\
**Category:** Elasticsearch\
**Created:** [July 22, 2013, 12:28pm UTC](https://discuss.elastic.co/t/how-to-implement-feature-change-in-results-after-clicking-a-facet/12877 "2013-07-22T12:28:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Crwe](https://avatars.discourse-cdn.com/v4/letter/c/898d66/32.png) [@Crwe](https://discuss.elastic.co/u/Crwe)\
**Post date:** [July 22, 2013, 12:28pm UTC](https://discuss.elastic.co/t/how-to-implement-feature-change-in-results-after-clicking-a-facet/12877/1 "2013-07-22T12:28:15Z")

</div>

Hello all,

our app displays "standard" facets along with counts at the moment:  
"_orange_ appears in _13_ documents" etc.

A new requirement came that a different number should be displayed.  
Basically for our queries, which will have the form of "(X1 OR X2 OR ...)  
AND (Y1 OR Y2 OR ...) AND ...", for each displayed facet value, we must  
show to customers the NUMBER OF RESULTS THAT WILL BE DISPLAYED AFTER SHE  
CLICKS ON THAT FACET VALUE.

Example: User is on a result page with 97 results, with already selected  
facets X1 and X2 for field X and Y1 and Y2 for field Y. If, after clicking  
on facet value "X3", which will result in query "(X1 OR X2 OR X3) AND (Y1  
OR Y2)", she'd see 124 results then we must display the number "+27"  
(=124-97), next to X3.

Another example: if after clicking on facet field Z with value "Z1", query  
"(X1 OR X2) AND (Y1 OR Y2) AND (Z1)", she'd see 33 results, we want to  
display the number "-64" (=33-97) next to Z1.

And so on. We display 5 not\_analyzed fields with 10 facet values each = ~50  
facet values on the result page.

I think one solution is to brute force an extra query for each possible  
facet value: X1, X2, X3, Y1, Y2, Y3, Z1, Z2, Z3..., recording just the  
number of results returned and throwing away the results. But that will be  
a lot of extra queries: 50 facet values = 50 extra queries.

Has anyone encountered this requirement before? Any ideas on how to achieve  
this functionality in a smarter way than brute force?

Cheers~

--  
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:25am UTC](https://discuss.elastic.co/t/how-to-implement-feature-change-in-results-after-clicking-a-facet/12877/2 "2017-07-06T02:25:13Z")

</div>


