# How to make Kibana Filters use Filter Context instead of Query Context?

**URL:** <https://discuss.elastic.co/t/how-to-make-kibana-filters-use-filter-context-instead-of-query-context/221430>\
**Category:** Kibana\
**Created:** [February 28, 2020, 1:05pm UTC](https://discuss.elastic.co/t/how-to-make-kibana-filters-use-filter-context-instead-of-query-context/221430 "2020-02-28T13:05:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rajiv](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rajiv/32/47644_2.png) [@Rajiv](https://discuss.elastic.co/u/Rajiv)\
**Post date:** [February 28, 2020, 1:05pm UTC](https://discuss.elastic.co/t/how-to-make-kibana-filters-use-filter-context-instead-of-query-context/221430/1 "2020-02-28T13:05:12Z")

</div>

We are using Kibana v6.8.1 to search log messages

When we try to filter messages using the "Filter for value" icon like so:  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/6/a/6ac9978b829702efd6d5629b2636eb2ca81e9eb6.png)

we notice Kibana generates search query with a match\_phrase clause in Query Context, like so:

> ` "query":{"bool":{"must":[{"match_phrase":{"fields.cloud_service":{"query":"query-service"}}},{"range":{"@timestamp":{"gte":1582892416657,"lte":1582893316657,"format":"epoch_millis"}}}],"filter":[{"match_all":{}}],"should":[],"must_not":[]}}`

The query clause triggers scoring and from search profiling we see that scoring is taking a lot of time

Instead of using Kibana UI filters, if we typed the lucene query `fields.cloud_service:query-service` in the Kibana text field, it is orders of magnitude faster. In this case Kibana generates a match\_phrase in Filter Context. Since this is running in Filter Context, there is no scoring involved and the search are much faster.

> ` "query":{"bool":{"must":[{"range":{"@timestamp":{"gte":1582893170986,"lte":1582894070986,"format":"epoch_millis"}}}],"filter":[{"bool":{"should":[{"match_phrase":{"fields.cloud_service":"query-service"}}],"minimum_should_match":1}}],"should":[],"must_not":[]}}`

Is there a reason why Kibana UI filters do not use Filter Context by default? Is there an option to force Kibana UI filters to use Filter Context instead of Query Context?

---

<div class="post-metadata">

**Author:** ![cheiligers](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cheiligers/32/73114_2.png) [@cheiligers](https://discuss.elastic.co/u/cheiligers)\
**Post date:** [February 28, 2020, 9:11pm UTC](https://discuss.elastic.co/t/how-to-make-kibana-filters-use-filter-context-instead-of-query-context/221430/2 "2020-02-28T21:11:51Z")

</div>

Dear Rajiv,  
Unfortunately, the behavior of filters when using Kibana KQL is set and cannot be configured to use the filter context. Fortunately, you've already found the workaround for 6.8.1! From [v7.4.0, filters use the correct context](https://github.com/elastic/kibana/pull/42095).

---

<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:** [March 27, 2020, 9:11pm UTC](https://discuss.elastic.co/t/how-to-make-kibana-filters-use-filter-context-instead-of-query-context/221430/3 "2020-03-27T21:11:59Z")

</div>

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