Create scripted field showing time differences

Hi everyone,

I am running Elastic Stack 7.9 with a basic license. In my data I have two date fields and I want to create a scripted field that writes the difference in a nice format. I easily get the difference by just substracting:

diff = doc['date_updated'].value.getMillis() - doc['date_create'].value.getMillis()

But I am trying to find a way to present the difference in a nice simple way, for example 1 day 3 hours. As I understand the documentation, formatting of date fields is done using momentjs, but how can I access it painless, and especially the diff method?

I have tried things such as (for simplicity ´date1, date2´ are the two target date field values):

var date1 = moment(doc['date_updated'].value.getMillis())

but it already here fails as it does not know moment.

What am I doing wrong, or is there any other obvious way to create my wanted scripted field?

Many thanks for any help!

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