# Script Field in Kibana with Time Passed Since Timestamp

**URL:** <https://discuss.elastic.co/t/script-field-in-kibana-with-time-passed-since-timestamp/36393>\
**Category:** Kibana\
**Created:** [December 4, 2015, 2:59pm UTC](https://discuss.elastic.co/t/script-field-in-kibana-with-time-passed-since-timestamp/36393 "2015-12-04T14:59:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ralph\_Vigne](https://avatars.discourse-cdn.com/v4/letter/r/90db22/32.png) [@Ralph\_Vigne](https://discuss.elastic.co/u/Ralph_Vigne)\
**Post date:** [December 4, 2015, 2:59pm UTC](https://discuss.elastic.co/t/script-field-in-kibana-with-time-passed-since-timestamp/36393/1 "2015-12-04T14:59:20Z")

</div>

Hi Experts,

I did quite an extensive search (Google and this forum) but to my surprise couldn't find anything.  
If I just asked the question the wring way please point me to the right thread or something.

What I wanted to do is to have a script field in Kibana (v4) showing me the time passed since the time indicated in a timestamp field of document. While I know how to handle timestamp values I couldn't figure out how to get the 'Now' timestamp to calculate the time passed since.

To provide some context: I'm tracking state changes of jobs by parsing log files. Each time the state of a job changes I update the according ES document with a matching timestamp (e.g. queued, active, done).

Now what I want is a data table showing me the e.g. the 10 events which are the longest in each state. I'd like to do this as it should allow to spot "hanging" events very easily, as they will bubble to the top of the table very soon (as my execution times are usually very similar).

Any help is very much appreciated.

Cheers and have a good weekend,  
Ralph

---

<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:** [December 9, 2015, 5:06am UTC](https://discuss.elastic.co/t/script-field-in-kibana-with-time-passed-since-timestamp/36393/2 "2015-12-09T05:06:18Z")

</div>

The default language in scripted fields is [Lucene expressions](https://lucene.apache.org/core/4_9_0/expressions/index.html?org/apache/lucene/expressions/js/package-summary.html), which at this time does not handle date math. We are working on [another scripting language](https://github.com/elastic/Painless) that will do that, but it's still ways away. For now, you can specify and use Groovy in your scripted fields, but for that you'd need to enable dynamic sandboxing (which has vulnerabilities) or use [static Groovy scripts](https://discuss.elastic.co/t/calling-groovy-script-from-kibana/2542).

---

<div class="post-metadata">

**Author:** ![Ralph\_Vigne](https://avatars.discourse-cdn.com/v4/letter/r/90db22/32.png) [@Ralph\_Vigne](https://discuss.elastic.co/u/Ralph_Vigne)\
**Post date:** [December 9, 2015, 3:44pm UTC](https://discuss.elastic.co/t/script-field-in-kibana-with-time-passed-since-timestamp/36393/3 "2015-12-09T15:44:14Z")

</div>

Hi Tanya,

thanks for responding. I'm not quite sure if we are talking about the same  
thing here. The date math functionality is good enough for me i.e.  
calculating the time delta of two timestamps works. Only thing I'm missing  
is the 'now' time, by which I mean the time the query is executed.

When I do this programmatically, everything's fine because I know 'now' and  
can calculate the delta, only in Kibana visualisations I don't know how to  
get it. Is it maybe possible to get some sort of 'virtual field'  
representing 'now' in the ES results? Then Kibana would be sufficient again.

Cheers,  
Ralph

---

<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:07pm UTC](https://discuss.elastic.co/t/script-field-in-kibana-with-time-passed-since-timestamp/36393/4 "2017-07-06T14:07:01Z")

</div>


