Calculate duration between two events using scripted fields

Hello is it possible to calculate the duration between two events (Dates) while using scripted fields and painless? I tried a lot but I can't get it working.

Yep, it can be done.
If you have two date fields (time1 and time2) you can write a script like this:
doc['time2'].value - doc['time1'].value
You'll also want to have the scripted field with
type: number
Format: Duration
InputFormat: seconds (if you use the date fields as normal UNIX timestamp)
OutputFormat: Human Readable

3 Likes

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