Is there any way to apply facets one-after-the-other in series?

I have a use case where I want to filter based on facet1 and if that doesn’t return anything, then I want to expand and add another filter2

Hello! Thanks for reaching out. Based on the limited use case you’ve outlined, I can suggest two possibilities - one simple, and one slightly more complex.

The easiest thing to do is to simply wrap some logic around the search such that if the results of the first search (on facet1) returns 0 results, execute another search (on facet2). This has the advantage of being very simple and easy to understand, as well was being lightweight in terms of added code since you don’t need to implement much parsing logic at all. On the downside, it will require you to make multiple search queries - but as long as each query is light, your performance shouldn’t suffer.

Another possibility is to make a query with both facets and then parse the results. If results from facet1 are present, display only those; if not, display those from facet2 instead. The most straightforward way to determine this would be to look at the result for the facets key, which will have a list of the chosen facets along with the number of hits from each as a numeric value. This has the advantage of requiring only one query; however it will require you to write much more parsing logic.

If you’re optimising for simplicity, the first example is better; if you’re optimising for query count, go with the second.

I hope that answers your question. If you need anything else, please don’t hesitate to ask.