# Pre-filter data for date\_histogram aggregations

**URL:** https://discuss.elastic.co/t/pre-filter-data-for-date-histogram-aggregations/47720
**Category:** Elasticsearch
**Created:** [April 18, 2016, 11:18pm UTC](https://discuss.elastic.co/t/pre-filter-data-for-date-histogram-aggregations/47720 "2016-04-18T23:18:50Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![rrva](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rrva/32/43888_2.png) [@rrva](https://discuss.elastic.co/u/rrva)
#### Post date: [April 18, 2016, 11:18pm UTC](https://discuss.elastic.co/t/pre-filter-data-for-date-histogram-aggregations/47720/1 "2016-04-18T23:18:50Z")

</div>

For 1.5, what is the preferred way to pre-filter the documents that a date\_histogram aggregation operates on?  
For example if I want to create 1-minute buckets only over documents with timestamp now-3615s to now-15s?

Is a nested aggregation with [https://www.elastic.co/guide/en/elasticsearch/reference/1.5/search-aggregations-bucket-filter-aggregation.html](https://www.elastic.co/guide/en/elasticsearch/reference/1.5/search-aggregations-bucket-filter-aggregation.html) as the outer value and date\_histogram as the inner aggregation the way to go?

Also, if filter aggregation is the way to go, and I want to use several date\_histogram aggregations with different extended\_bounds, but the same interval length, are there any issues with nesting them all under the same filter aggregation?

Performance-wise, when using date-partitioned indices, based a timestamp field, can timestamp range filters or filter aggregations use some internal optimization to automatically determine which indices do not need to be considered for a query, or is it better to pre-select the indices by date which you know upfront contain the selected time range?

---

<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, 10:58pm UTC](https://discuss.elastic.co/t/pre-filter-data-for-date-histogram-aggregations/47720/2 "2017-07-05T22:58:21Z")

</div>


