Extracting hour from date field (scripted field)


Is there a way to extract the hour from the timestamp field using a scripted field? I saw a blog post stating that this could be done a while back but it looks like it used groovy which is no longer supported.. is there a way to do it on the latest release? At the moment i am creating this field during the import but it is hard to get it to work for different timezones ( i have to create a field for each zone that i know will be used and then make a different visualization for each of those fields)

Also is there a way (using scripted fields) to get time duration in minutes from two different timedate fields?


This is not currently possible, we're working to bring date support into scripts.

Currently, no. We supported groovy scripting in the early Kibana 4 betas but since it is no longer enabled by default we have dropped support. We expect the lucene expression syntax to grow over time though, and might someday support some form of date transformation. For now though you should use something (maybe logstash) to preprocess your documents and add the hour as it's own field.

You can subtract two timestamps to get the number of seconds between them, but not the number of minutes.

OK thank you. Looking forward to the next release (or one after that)

Hello Rashid,

This should be suopported now as per the following link:

However, I have tried adding a scripted field as in the forementioned link in order to extract hour of the day, i.e. using the following script:
Integer.parseInt(new Date(doc["@timestamp"].value).format("H"))
but I got an error that the scripted field cannot be evaluated. Do you know what the problem is? I am using Kibana version 4.5.1

Hello Mahdy, for the record, i managed to accomplish that using the following expression

Integer.parseInt(new SimpleDateFormat("HH").format(new Date(doc["created_on"].value)))