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

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.
For more options, visit https://groups.google.com/groups/opt_out.