# Filtering to include only records in 5-minute intervals using a date field

**URL:** <https://discuss.elastic.co/t/filtering-to-include-only-records-in-5-minute-intervals-using-a-date-field/231652>\
**Category:** Kibana\
**Created:** [May 8, 2020, 2:41am UTC](https://discuss.elastic.co/t/filtering-to-include-only-records-in-5-minute-intervals-using-a-date-field/231652 "2020-05-08T02:41:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sreliable](https://avatars.discourse-cdn.com/v4/letter/s/ecd19e/32.png) [@sreliable](https://discuss.elastic.co/u/sreliable)\
**Post date:** [May 8, 2020, 2:41am UTC](https://discuss.elastic.co/t/filtering-to-include-only-records-in-5-minute-intervals-using-a-date-field/231652/1 "2020-05-08T02:41:11Z")

</div>

Hi all,

Currently all my documents in my index contain the `CleanDate` field which is date type:

`{"CleanDate" : "2020-04-24T05:42:00.000Z"}`

My documents are being shipped into elasticsearch every minute.  
Is there a way for me to include a filter on visualizations/dashboard to only include documents with CleanDate that are multiples of 5minutes?

ie.

Accepted

> "2020-04-24T05:00:00.000Z"  
> "2020-04-24T05:05:00.000Z"  
> "2020-04-24T05:10:00.000Z"  
> "2020-04-24T05:15:00.000Z"

Rejected

> "2020-04-24T05:01:00.000Z"

**Solutioning**

I have tried filtering by scripted fields as below:

`return doc['CleanDate'].value.getMinute();`

This does return the minute, however when I try to filter them using the filter UI icon, no records show up.

I've also tried using the following scripted field as per documentation to no luck:  
`return doc['CleanDate'].date.minuteOfHour;`  
This does not return anything -

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

Please help. Thanks!

---

<div class="post-metadata">

**Author:** ![flash1293](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flash1293/32/41227_2.png) [@flash1293](https://discuss.elastic.co/u/flash1293)\
**Post date:** [May 8, 2020, 7:39am UTC](https://discuss.elastic.co/t/filtering-to-include-only-records-in-5-minute-intervals-using-a-date-field/231652/2 "2020-05-08T07:39:56Z")

</div>

The first script using `getMinute` looks right to me. I tested it locally and it worked fine:

 ![Screenshot 2020-05-08 at 09.33.45](https://us1.discourse-cdn.com/elastic/original/3X/8/5/856bc7d748f45a5c77133e9619cffa7631f0eac6.png) ![Screenshot 2020-05-08 at 09.33.54](https://us1.discourse-cdn.com/elastic/original/3X/c/d/cd7946c12cf7fcb85013e93b1372d904ce37e767.png) ![Screenshot 2020-05-08 at 09.34.06](https://us1.discourse-cdn.com/elastic/original/3X/a/a/aa77fc5d6a3bfa30640b08b638f896918bc875ea.png)

I'm just guessing at that point, but did you try to use multiple filters like this?  
 ![Screenshot 2020-05-08 at 09.35.27](https://us1.discourse-cdn.com/elastic/original/3X/b/3/b37ea5f4549a629c93f4d68a50f801a994eb81f6.png)

That wouldn't work, because these filters are connected by "AND"s - each document has to match all of them. As no document can have both value 28 and 30 as "minute", no results show up.

I recommend the following - create a scripted field of type boolean called `is5MinuteMultiple` with the following script:

`return doc['CleanDate'].value.getMinute() % 5 == 0;`

Then filter by this field getting true:

 ![Screenshot 2020-05-08 at 09.39.32](https://us1.discourse-cdn.com/elastic/original/3X/c/a/ca4f1ef2118f7c522eee154ea2937569260de7ae.png)

---

<div class="post-metadata">

**Author:** ![sreliable](https://avatars.discourse-cdn.com/v4/letter/s/ecd19e/32.png) [@sreliable](https://discuss.elastic.co/u/sreliable)\
**Post date:** [May 8, 2020, 9:44am UTC](https://discuss.elastic.co/t/filtering-to-include-only-records-in-5-minute-intervals-using-a-date-field/231652/3 "2020-05-08T09:44:46Z")

</div>

Hey Joe,

I did not try using multiple filters like that, its weird but even when I put a simple filter like `minute exists`, it would show `No results found`.

Anyway, I tried your solution and it worked like a charm 🙂  
Thanks for the advice!

---

<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:** [June 5, 2020, 9:44am UTC](https://discuss.elastic.co/t/filtering-to-include-only-records-in-5-minute-intervals-using-a-date-field/231652/4 "2020-06-05T09:44:52Z")

</div>

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