Getting list of valid filters/facets with search results

I am using App Search via a manual API integration on Elastic Stack 7.8.0.

I understand how to use filter and facets to narrow down the focus of any search query, but how do I get a list of filters/facets that are contextually relevant only to the current search?

For example, let's say I sell thousands of shoes in a variety of 100 colours. When the user searches for the term sneaker, the search query returns 100 products, and all of them just so happen to be in only the colours black, white and orange.

In designing my interface to allow users to filter the search results (which are paginated to 20 products at a time), it doesn't make any sense to show a list of 100 colour options - I only want to show the 3 colours that are contextually relevant to the search term they are currently on.

How do I get the list of those three colours that apply to the current search?

This seems quite basic, but yet I cannot seem to find the reference on how to do this. Please help!

I suspect any irrelevant facets you are seeing are a side effect of the fuzzy matching approach used by default.
See this comment on making the query less fuzzy to increase precision. This will help remove irrelevant facets.

When the user searches for the term sneaker , the search query returns 100 products, and all of them just so happen to be in only the colours black, white and orange.

How do I get the list of those three colours that apply to the current search?

If you perform a search which results in 100 products that just so happen to be in only the colors black, white, and orange, then you should only see those 3 options in your color facet. You should not be seeing all 100 color options. The guide on faceting is here, for reference.

As Mark mentioned, it may appear that this is not the case if you have a very large result set.

Okay, thanks guys. I am doing things very wrong - thanks for the guidance!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.