# Getting list of valid filters/facets with search results

**URL:** <https://discuss.elastic.co/t/getting-list-of-valid-filters-facets-with-search-results/245543>\
**Category:** Elastic Search\
**Tags:** elastic-app-search\
**Created:** [August 19, 2020, 8:07am UTC](https://discuss.elastic.co/t/getting-list-of-valid-filters-facets-with-search-results/245543 "2020-08-19T08:07:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![SCP](https://avatars.discourse-cdn.com/v4/letter/s/c37758/32.png) [@SCP](https://discuss.elastic.co/u/SCP)\
**Post date:** [August 19, 2020, 8:07am UTC](https://discuss.elastic.co/t/getting-list-of-valid-filters-facets-with-search-results/245543/1 "2020-08-19T08:07:44Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [August 19, 2020, 9:16am UTC](https://discuss.elastic.co/t/getting-list-of-valid-filters-facets-with-search-results/245543/2 "2020-08-19T09:16:44Z")

</div>

> [@SCP](#):
>
> how do I get a list of filters/facets that are **contextually relevant** only to the current search?

I suspect any irrelevant facets you are seeing are a side effect of the fuzzy matching approach used by default.  
See [this comment](https://discuss.elastic.co/t/options-for-increasing-precision/219920/5) on making the query less fuzzy to increase precision. This will help remove irrelevant facets.

---

<div class="post-metadata">

**Author:** ![JasonStoltz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jasonstoltz/32/49893_2.png) [@JasonStoltz](https://discuss.elastic.co/u/JasonStoltz)\
**Post date:** [August 19, 2020, 12:24pm UTC](https://discuss.elastic.co/t/getting-list-of-valid-filters-facets-with-search-results/245543/3 "2020-08-19T12:24:50Z")

</div>

> 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](https://swiftype.com/documentation/app-search/guides/facets) is here, for reference.

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

---

<div class="post-metadata">

**Author:** ![SCP](https://avatars.discourse-cdn.com/v4/letter/s/c37758/32.png) [@SCP](https://discuss.elastic.co/u/SCP)\
**Post date:** [August 19, 2020, 1:04pm UTC](https://discuss.elastic.co/t/getting-list-of-valid-filters-facets-with-search-results/245543/4 "2020-08-19T13:04:23Z")

</div>

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

---

<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:** [September 16, 2020, 1:04pm UTC](https://discuss.elastic.co/t/getting-list-of-valid-filters-facets-with-search-results/245543/5 "2020-09-16T13:04:25Z")

</div>

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