# Filter on a datefield relative to today

**URL:** <https://discuss.elastic.co/t/filter-on-a-datefield-relative-to-today/79559>\
**Category:** Kibana\
**Created:** [March 22, 2017, 9:39am UTC](https://discuss.elastic.co/t/filter-on-a-datefield-relative-to-today/79559 "2017-03-22T09:39:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cylindric](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cylindric/32/5660_2.png) [@Cylindric](https://discuss.elastic.co/u/Cylindric)\
**Post date:** [March 22, 2017, 9:39am UTC](https://discuss.elastic.co/t/filter-on-a-datefield-relative-to-today/79559/1 "2017-03-22T09:39:30Z")

</div>

I have a dataset that includes various date fields, and I would like to only show records where the date is "recent". I can get the data using the date math stuff from the [Range Query](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-query.html) docs:

```
GET ipreputation-*/_search
{
    "query": {
        "range" : {
            "status_changed" : {
                "gt" : "now-1d/d",
                "lte" : "now/d"
            }
        }
    }
}

```

But how can I do that in the Discover section of Kibana? The Kibana docs are very light on what can go in that query bar.

---

<div class="post-metadata">

**Author:** ![Marius\_Dragomir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marius_dragomir/32/42087_2.png) [@Marius\_Dragomir](https://discuss.elastic.co/u/Marius_Dragomir)\
**Post date:** [March 22, 2017, 11:26am UTC](https://discuss.elastic.co/t/filter-on-a-datefield-relative-to-today/79559/2 "2017-03-22T11:26:04Z")

</div>

If the time field that you want to filter on ("status\_changed") is the one set when you created the index pattern in Kibana, you can filter the Discover or any other section of Kibana by using the timepicker in the upper right of the page.  
That has the option to use relative time periods for filtering.

 ![](https://us1.discourse-cdn.com/elastic/original/3X/b/0/b0cd635498cc1c919f71f251ae554ff70c50e45c.png)

---

<div class="post-metadata">

**Author:** ![Cylindric](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cylindric/32/5660_2.png) [@Cylindric](https://discuss.elastic.co/u/Cylindric)\
**Post date:** [March 22, 2017, 11:27am UTC](https://discuss.elastic.co/t/filter-on-a-datefield-relative-to-today/79559/3 "2017-03-22T11:27:53Z")

</div>

No this has nothing to do with that. This could one of any number of different date fields.  
This is about doing the sort of date queries that I described in my original question.

---

<div class="post-metadata">

**Author:** ![Marius\_Dragomir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marius_dragomir/32/42087_2.png) [@Marius\_Dragomir](https://discuss.elastic.co/u/Marius_Dragomir)\
**Post date:** [March 22, 2017, 12:48pm UTC](https://discuss.elastic.co/t/filter-on-a-datefield-relative-to-today/79559/4 "2017-03-22T12:48:59Z")

</div>

Oh, OK, I understand what you mean now.  
There's a solution to that on the Discover field.  
You create a pinned filter on the page and then edit it and add your own range math.  
To add a filter you expand a document in the Discover field and in the table containing all the fields you can click on the magnifying glass with the plus in to add an "include" filter and the one with the minus to add an "exclude" one.  
[https://www.elastic.co/guide/en/kibana/current/field-filter.html](https://www.elastic.co/guide/en/kibana/current/field-filter.html)

 ![](https://us1.discourse-cdn.com/elastic/original/3X/d/8/d8d62da4b1088d664f7e2d5563bbfe906ab743a6.png)

---

<div class="post-metadata">

**Author:** ![Cylindric](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cylindric/32/5660_2.png) [@Cylindric](https://discuss.elastic.co/u/Cylindric)\
**Post date:** [March 22, 2017, 12:52pm UTC](https://discuss.elastic.co/t/filter-on-a-datefield-relative-to-today/79559/5 "2017-03-22T12:52:32Z")

</div>

Oh, that's perfect, thanks. I hadn't spotted that button on the filtered items before.

---

<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 19, 2017, 12:52pm UTC](https://discuss.elastic.co/t/filter-on-a-datefield-relative-to-today/79559/6 "2017-04-19T12:52:39Z")

</div>

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