# Is it possible to have a time filter based on an integer field?

**URL:** <https://discuss.elastic.co/t/is-it-possible-to-have-a-time-filter-based-on-an-integer-field/151021>\
**Category:** Kibana\
**Created:** [October 4, 2018, 10:10am UTC](https://discuss.elastic.co/t/is-it-possible-to-have-a-time-filter-based-on-an-integer-field/151021 "2018-10-04T10:10:48Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![OphyTe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ophyte/32/36444_2.png) [@OphyTe](https://discuss.elastic.co/u/OphyTe)\
**Post date:** [October 4, 2018, 10:10am UTC](https://discuss.elastic.co/t/is-it-possible-to-have-a-time-filter-based-on-an-integer-field/151021/1 "2018-10-04T10:10:48Z")

</div>

Hi,

I have an integer field which store a date in UNIX\_MS format (number of milliseconds since epoch).  
How can I do to base my time filter on it ?

Do I have to duplicate the field in a Date format ? Isn't that heavy to duplicate field in elastic just for visualization purposes ?

---

<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:** [October 4, 2018, 10:53am UTC](https://discuss.elastic.co/t/is-it-possible-to-have-a-time-filter-based-on-an-integer-field/151021/2 "2018-10-04T10:53:00Z")

</div>

Elastic date fields do exactly that, store the data in UNIX\_MS format. [https://www.elastic.co/guide/en/elasticsearch/reference/current/date.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/date.html)  
At ingest you should just set this as a date field so you don't have it as integer. The purpose of a date field specifically is to handle timezones and DST based on ingest.

---

<div class="post-metadata">

**Author:** ![OphyTe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ophyte/32/36444_2.png) [@OphyTe](https://discuss.elastic.co/u/OphyTe)\
**Post date:** [October 5, 2018, 3:41pm UTC](https://discuss.elastic.co/t/is-it-possible-to-have-a-time-filter-based-on-an-integer-field/151021/3 "2018-10-05T15:41:33Z")

</div>

Unfortunately I have no choice on the field type. The elastic index is built by a client app which extract data from an Oracle database and put it in the elastic with an obscure library which rest on a mapper which convert Date into Long ... no comment 😒

---

<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:** [October 5, 2018, 3:47pm UTC](https://discuss.elastic.co/t/is-it-possible-to-have-a-time-filter-based-on-an-integer-field/151021/4 "2018-10-05T15:47:20Z")

</div>

you should be able to create a scripted field in Kibana, that gets the value of that field and sets it as Date field.

---

<div class="post-metadata">

**Author:** ![OphyTe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ophyte/32/36444_2.png) [@OphyTe](https://discuss.elastic.co/u/OphyTe)\
**Post date:** [October 5, 2018, 4:27pm UTC](https://discuss.elastic.co/t/is-it-possible-to-have-a-time-filter-based-on-an-integer-field/151021/5 "2018-10-05T16:27:21Z")

</div>

I did but how can I define this Date field as the time-field on which the time filter is based?

It seems that this time field has to be define with the index pattern definition and that we can not go back on it. As for the scripted field, it's defined once the index pattern is!

Here is my scripted field :

```
new Date(doc['myField'].value)`

```

I also read somewhere that scripted field are resource gready so I'm not sure this can be a valid solution.

---

<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:** [October 9, 2018, 12:16pm UTC](https://discuss.elastic.co/t/is-it-possible-to-have-a-time-filter-based-on-an-integer-field/151021/6 "2018-10-09T12:16:27Z")

</div>

Yes, you are indeed right. The scripted fields will be resource intensive. Unfortunately, I can't think of any other solution that Kibana can provide for this. You can look into the Elastic ingest pipelines (but this will only work at data ingest, so you can't transform the existing data): [https://www.elastic.co/blog/new-way-to-ingest-part-1](https://www.elastic.co/blog/new-way-to-ingest-part-1) as I think they should be able to transform the integer field to a date field.

---

<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:** [November 6, 2018, 12:16pm UTC](https://discuss.elastic.co/t/is-it-possible-to-have-a-time-filter-based-on-an-integer-field/151021/7 "2018-11-06T12:16:27Z")

</div>

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