# Filter out buckets in a date\_histogram aggregated query

**URL:** https://discuss.elastic.co/t/filter-out-buckets-in-a-date-histogram-aggregated-query/223869
**Category:** Elasticsearch
**Created:** [March 17, 2020, 8:02am UTC](https://discuss.elastic.co/t/filter-out-buckets-in-a-date-histogram-aggregated-query/223869 "2020-03-17T08:02:35Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![ajacob](https://avatars.discourse-cdn.com/v4/letter/a/e19b73/32.png) [@ajacob](https://discuss.elastic.co/u/ajacob)
#### Post date: [March 17, 2020, 8:02am UTC](https://discuss.elastic.co/t/filter-out-buckets-in-a-date-histogram-aggregated-query/223869/1 "2020-03-17T08:02:35Z")

</div>

Hello !

I have documents with a field that can store multiple dates like this:

```auto
{
	"documentId": 481012,
	"creationDate": "2016-06-02T17:30:34.232Z",
	"activationDates": [
		"2016-06-02T17:30:34.232Z",
		"2016-06-03T17:30:34.232Z",
		"2016-06-04T17:30:34.232Z",
		"2016-06-05T17:30:34.232Z",
		"2016-06-06T17:30:34.232Z",
               ...
	]
}

```

Now I want to make a date\_histogram aggregation on them, here is the query I'm using:

```auto
{
	"aggs": {
		"day_aggregation": {
			"date_histogram": {
				"field": "activationDates",
				"interval" : "day"
			}
		}
	}
}

```

The result is a list of buckets with a bucket for each date (as a day) present in all documents matching the query (all of them in this example because there is no filtering).

In my use case, I'd like to be able to have only 2016-06-03, 2016-06-04 and 2016-06-05 buckets in my final result. I can do this afterward in the application code but it would be better do do this in the query, if possible of course.

Is it possible to remove unwanted buckets ?

Here is a link of what I'd like to do: [Filter out buckets in an aggregated query](https://discuss.elastic.co/t/filter-out-buckets-in-an-aggregated-query/25327)

But in his case he is working with terms aggregation and can simply use include/exclude. In my case I think it would be better to be able to filter out the unwanted buckets with range queries.

Any highlight would be appreciated, thank you !

---

<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: [April 14, 2020, 8:02am UTC](https://discuss.elastic.co/t/filter-out-buckets-in-a-date-histogram-aggregated-query/223869/2 "2020-04-14T08:02:38Z")

</div>

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