# Filtering on date = max\_date

**URL:** <https://discuss.elastic.co/t/filtering-on-date-max-date/28979>\
**Category:** Kibana\
**Created:** [September 9, 2015, 11:47pm UTC](https://discuss.elastic.co/t/filtering-on-date-max-date/28979 "2015-09-09T23:47:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mendeza](https://avatars.discourse-cdn.com/v4/letter/m/ed655f/32.png) [@mendeza](https://discuss.elastic.co/u/mendeza)\
**Post date:** [September 9, 2015, 11:47pm UTC](https://discuss.elastic.co/t/filtering-on-date-max-date/28979/1 "2015-09-09T23:47:16Z")

</div>

**Short version** : How do I create a "saved search" that filters based on the most recent date available?

**Long version** : I have a daily PIG job that updates ES based on the today's date. The problem is that sometimes the job fails and no data is updated for several days. So I want Kibana to filter based _only_ on the data with the latest date, regardless of whether it's from today or a week ago. Is it possible and if so, how?

From what I've read [here](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-max-aggregation.html), I can retrieve the max "date" value with something like this: { "aggs" : { "max\_date" : { "max" : { "field" : "date" } } } }. However, I'm not sure how to assign the max\_date value to my filter.

Thanks!  
Alvaro

---

<div class="post-metadata">

**Author:** ![tbragin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tbragin/32/45166_2.png) [@tbragin](https://discuss.elastic.co/u/tbragin)\
**Post date:** [September 12, 2015, 11:06pm UTC](https://discuss.elastic.co/t/filtering-on-date-max-date/28979/2 "2015-09-12T23:06:30Z")

</div>

You can't use aggregations in the filter search bar. To my knowledge, there is currently no way to dynamically change the time picker range based on the data.

Please feel free to submit an enhancement request (and contribute a PR!), if this is important to you: [https://github.com/elastic/kibana/issues](https://github.com/elastic/kibana/issues)

---

<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 6, 2017, 2:13pm UTC](https://discuss.elastic.co/t/filtering-on-date-max-date/28979/3 "2017-07-06T14:13:10Z")

</div>


