Creating a new field through painless scripts to calculate the difference between two timestamp

Hi all,

i am trying to create a new field (time_difference) in Kibana 7.4.2 to calculate the difference between two timestamp.

image

First i tried this

doc['@timestamp'].value - doc['p.dateTimeSend'].value

and i received
Script is invalid. View script preview for details

i also tried:
doc['@timestamp'].value.getMillis() - doc['p.dateTimeSend'].value.getMillis()

and i receive the same resut: Script is invalid. View script preview for details

Please tell me what is wrong with my script.
Thanks in advance!

Hi everyone,

I think i find out why my script is invalid. It is because my second timestamp (p.dateTimeSend or payload.dateTimeSend).

When i execute only doc['@timestamp'].value.toInstant().toEpochMilli() it works but when i execute doc['p.dateTimeSend'].value.toInstant().toEpochMilli() or doc['payload.dateTimeSend'].value.toInstant().toEpochMilli() it don´t work.

Somebody know why payload.dateTimeSend is not working?
how can i remove in all field the p. or payload. ?
Thanks in advance!

Is the Payload field a nested field? Then that might be the issue.
From what I see this should really work:
doc['@timestamp'].value.toInstant().toEpochMilli() - doc['utc_time'].value.toInstant().toEpochMilli()

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