# Do post\_filter queries run under query context or filter context?

**URL:** https://discuss.elastic.co/t/do-post-filter-queries-run-under-query-context-or-filter-context/165913
**Category:** Elasticsearch
**Created:** [January 27, 2019, 3:31pm UTC](https://discuss.elastic.co/t/do-post-filter-queries-run-under-query-context-or-filter-context/165913 "2019-01-27T15:31:49Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![tmenier](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tmenier/32/34447_2.png) [@tmenier](https://discuss.elastic.co/u/tmenier)
#### Post date: [January 27, 2019, 3:31pm UTC](https://discuss.elastic.co/t/do-post-filter-queries-run-under-query-context-or-filter-context/165913/1 "2019-01-27T15:31:49Z")

</div>

According to [https://www.elastic.co/guide/en/elasticsearch/reference/current/query-filter-context.html:](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-filter-context.html:)

> Filter context is in effect whenever a query clause is passed to a `filter` parameter, such as the `filter` or `must_not` parameters in the `bool` query, the `filter` parameter in the `constant_score` query, or the `filter` aggregation.

What about queries under `post_filter`? Should I infer from the name that these will be under filter context? I could imagine cases where you might want scoring here, so I just wanted to be sure. Thanks!

---

<div class="post-metadata">

### Author: ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)
#### Post date: [January 28, 2019, 10:39pm UTC](https://discuss.elastic.co/t/do-post-filter-queries-run-under-query-context-or-filter-context/165913/2 "2019-01-28T22:39:14Z")

</div>

The queries added to the a`post_filter` will be entirely in the "filter" context (e.g. non-scoring). The `post_filter` only exists to allow filtering the search hit results differently from the agg results. But the ranking/scoring of those results don't matter since aggs collect _any_ matching document regardless of their score.

E.g. if you want agg results to be filtered in a certain way, you can include that in the regular `query`. If you want the search results to be filtered but the aggs to represent all the data, use a `post_filter`. The actual ranking of the search results is unimportant to aggregations, so you can include the necessary scoring elements in the regular `query`.

Hope that helps! It's a little hard to explain 🙂

---

<div class="post-metadata">

### Author: ![tmenier](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tmenier/32/34447_2.png) [@tmenier](https://discuss.elastic.co/u/tmenier)
#### Post date: [January 28, 2019, 11:05pm UTC](https://discuss.elastic.co/t/do-post-filter-queries-run-under-query-context-or-filter-context/165913/3 "2019-01-28T23:05:05Z")

</div>

Yes, that answers it perfectly. Thanks!

---

<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: [February 25, 2019, 11:05pm UTC](https://discuss.elastic.co/t/do-post-filter-queries-run-under-query-context-or-filter-context/165913/4 "2019-02-25T23:05:12Z")

</div>

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