# How filter an aggregation result

**URL:** https://discuss.elastic.co/t/how-filter-an-aggregation-result/29026
**Category:** Elasticsearch
**Created:** [September 10, 2015, 12:25pm UTC](https://discuss.elastic.co/t/how-filter-an-aggregation-result/29026 "2015-09-10T12:25:18Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Jean\_Szabo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jean_szabo/32/853_2.png) [@Jean\_Szabo](https://discuss.elastic.co/u/Jean_Szabo)
#### Post date: [September 10, 2015, 12:25pm UTC](https://discuss.elastic.co/t/how-filter-an-aggregation-result/29026/1 "2015-09-10T12:25:18Z")

</div>

I have a query that return the max date from articles by blog.

But I want only the blogs that don't have any new article from 1 month ago.

```
   GET article_stats/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "blog_disabled": false
          }
        }
      ]
    }
  },
  "aggs": {
    "blog_id": {
        "terms": {
          "field": "blog_slug",
          "size": 1000
        },
        "aggs": {
          "max_date": {
            "max": {
              "field": "date"
            }
          }
        }
      }
      },
  "size": 0
}

```

Is it possible to filter the result of the aggregation for having only the blog with article older than 1 month ?

Jean

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [September 10, 2015, 1:57pm UTC](https://discuss.elastic.co/t/how-filter-an-aggregation-result/29026/2 "2015-09-10T13:57:34Z")

</div>

Use a filter aggregation: [https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filter-aggregation.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filter-aggregation.html)  
And add your date filter in it.

This should work.

---

<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: [July 5, 2017, 11:51pm UTC](https://discuss.elastic.co/t/how-filter-an-aggregation-result/29026/3 "2017-07-05T23:51:15Z")

</div>


