<commit_before>[[search-request-post-filter]]
=== Post filter

The `post_filter` allows any filter that it holds to be executed as last filter, because
of this the `post_filter` only has affect on the search hits and not facets.

There are several reasons why to specify filters as `post_filter`. One reason is to force
expensive filters to be executed as last filter, so that these filters only operate on the
docs that match with the rest of the query. An example of for what filter a post_filter
should be used for this reason is the `geo_distance` filter. The `geo_distance` filter is
in general an expensive filter to execute and to reduce the execution time for this filter,
one can choose to specify it as `post_filter`, so it runs on documents that are very likely
to be end up as matching documents.

Another important reason is when doing things like facet navigation,
sometimes only the hits are needed to be filtered by the chosen facet,
and all the facets should continue to be calculated based on the original query.
The `post_filter` element within the search request can be used to accomplish it.

Note, this is different compared to creating a `filtered` query with the
filter, since this will cause the facets to only process the filtered
results.

For example, let's create two tweets, with two different tags:

[source,js]
--------------------------------------------------
curl -XPUT 'localhost:9200/twitter/tweet/1' -d '
{
    "message" : "something blue",
    "tag" : "blue"
}
'<commit_msg>[DOCS] Fixed typo in post-filter.asciidoc<commit_after>[[search-request-post-filter]]
=== Post filter

The `post_filter` allows any filter that it holds to be executed as last filter, because
of this the `post_filter` only has affect on the search hits and not facets.

There are several reasons why to specify filters as `post_filter`. One reason is to force
expensive filters to be executed as last filter, so that these filters only operate on the
docs that match with the rest of the query. An example of for what filter a post_filter
should be used for this reason is the `geo_distance` filter. The `geo_distance` filter is
in general an expensive filter to execute and to reduce the execution time for this filter,
one can choose to specify it as `post_filter`, so it runs on documents that are very likely
to end up as matching documents.

Another important reason is when doing things like facet navigation,
sometimes only the hits are needed to be filtered by the chosen facet,
and all the facets should continue to be calculated based on the original query.
The `post_filter` element within the search request can be used to accomplish it.

Note, this is different compared to creating a `filtered` query with the
filter, since this will cause the facets to only process the filtered
results.

For example, let's create two tweets, with two different tags:

[source,js]
--------------------------------------------------
curl -XPUT 'localhost:9200/twitter/tweet/1' -d '
{
    "message" : "something blue",
    "tag" : "blue"
}
'
{'fraction_non_alphanumeric': 0.08325139298590627, 'fraction_numerical': 0.0032776138970829235, 'mean_word_length': 3.7836990595611284, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7583505', 'n_tokens_mistral': 771, 'n_tokens_neox': 741, 'n_words': 461}