Visualization with Date different between 2 fields

Hi there
I have 2 Date fields Field1 and Field2 and LABEL. I need to have a visualization which is a list which shows the difference in seconds for all the items:

|Items| timeTakeninSeconds|
|LABEL1| (Field2-Field1).seconds|
|LABEL2| (Field2-Field1).seconds|
|LABEL3| (Field2-Field1).seconds|

I tried with scripted field but come with error:
Discover: class_cast_exception: Cannot apply [-] operation to types [org.joda.time.MutableDateTime] and [org.joda.time.MutableDateTime].

Can you please help me with this.


Can you provide a copy of the script that you tried?

What version of kibana are you using?

Try adding getMillis to convert MutableDateTime to milliseconds

I am using Version: 6.3.1
my Script :
doc['LastHeartbeatCheck'].value - doc['currentTimesStamp'].value

type: number
Format: Duration
InputFormat: seconds
OutputFormat: Human Readable

the 2 fields (LastHeartbeatCheck, currentTimesStamp) are date fields... with value for eg
LastHeartbeatCheck = August 9th 2018, 15:00:12.000
currentTimesStamp=August 9th 2018, 15:00:12.000

Thanks Nathan for the idea of using .getMillis()

I update dthe script as follows and it worked:
doc['LastHeartbeatCheck'].value.getMillis() - doc['LastHeartbeatCheck'].value.getMillis()

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