Get non-selected facet values

We tried to create facets with multiple options:

=== Document Type ===
[ ] Word (42)
[x] PDF  (96)
[ ] Excel(11)
[ ] HTML (63)

Unfortunately if you select one facet, you do not get the counts for other facet values. Is it possible to get values and counts for not selected facets?

The API will not return the other values once you apply one of them as a filter, but you can cache them yourself in the UI. After the results reload, continue to display the original list of filters, with some of them selected and some not, accordingly. Once the user changes the main query, reset the cached list and start over.

I’m curious; this is a core feature of elasticsearch (facets + aggregations). Why is the API limited to not use this features?

Swiftype was originally built on an older version of Elastic. I believe there are efforts to upgrade it to a more current version but I have no specific information.

I would also like to be able to get non-selected facet values.

I am loading search results based on the URL, so users can bookmark or share the URL and get results with all filters applied. The way this API is currently built, that would require me to run two API calls if their bookmarked URL is faceted. The first unfiltered one gets all the facet result counts, and the second gets the filtered results.

Unless I’m missing something?

@stefan I’m curious, how would you accomplish this in Elasticsearch? If you apply a filter on a field and also a terms aggregation on the same field, I believe that would result in just the counts for the current result set. So going back to the original example, it would end up looking something like:

=== Document Type ===
[x] PDF  (96)

@micah.herstand Are you using App Search or Site Search? There is a solution for this with App Search, called “Disjunctive Faceting”. It will run separate queries, as you describe @micah.herstand, to achieve this automatically. It leverages caching to reduce additional network traffic this causes.

It’s currently available in the 2.0 version of the JavaScript API client. GitHub - swiftype/swiftype-app-search-javascript: Swiftype App Search Javascript Client

1 Like