# Post filter not returning expected results

**URL:** <https://discuss.elastic.co/t/post-filter-not-returning-expected-results/167414>\
**Category:** Elasticsearch\
**Created:** [February 7, 2019, 10:05am UTC](https://discuss.elastic.co/t/post-filter-not-returning-expected-results/167414 "2019-02-07T10:05:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![shubh235](https://avatars.discourse-cdn.com/v4/letter/s/7cd45c/32.png) [@shubh235](https://discuss.elastic.co/u/shubh235)\
**Post date:** [February 7, 2019, 10:05am UTC](https://discuss.elastic.co/t/post-filter-not-returning-expected-results/167414/1 "2019-02-07T10:05:03Z")

</div>

Hi,

I want to filter the stats returned by the extended stats aggregation. I basically need to filter out all values of avg that are 0.

Below is the query on which I need to apply the post filter but I am not sure how should I apply the post filter when I want to filter out a particular value. Could you please help. Thanks in advance.

```
    "aggs": {
      "variable_grp": {
        "terms": {
          "field": "variable",
          "size": 200,
          "order": { "stats.avg": "asc" }
        },
        "aggs": {
          "stats": {
            "extended_stats": { "field": "value_num" }
          }
        }
      }
    }, 
    "size":0
```

---

<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:** [February 15, 2019, 7:47pm UTC](https://discuss.elastic.co/t/post-filter-not-returning-expected-results/167414/2 "2019-02-15T19:47:53Z")

</div>

You'll need to use a [BucketSelector pipeline agg](https://www.elastic.co/guide/en/elasticsearch/reference/6.6/search-aggregations-pipeline-bucket-selector-aggregation.html), not the `post_filter`.

A post filter is used to filter the search hits _after_ aggregation results have run. It's often used for faceted navigation, so that clicking on a navigation facet in a UI changes the search results without changing the facets.

In your case, you want to "prune" out buckets with a specific value, which is what the `bucket_selector` pipeline agg does 🙂

---

<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 15, 2019, 7:48pm UTC](https://discuss.elastic.co/t/post-filter-not-returning-expected-results/167414/3 "2019-03-15T19:48:06Z")

</div>

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