Trying to calculate time difference using scripted fields

Hi i am trying to calculate time difference between two fields:
netflow.first_switched Sep 2, 2019 @ 16:25:51.000
netflow.last_switched Sep 2, 2019 @ 16:25:52.182
I am using:
but I am not getting any value while previewing result.
Specifications are as follows:

Hi Vikash

There are good examples in the painless documentation how to solve this:
Did you have a look?
If it doesn't work, maybe you could paste a sample Elasticsearch document here, so I could try it out. the dates you've pasted look formatted.

@matw I have tried the document still didn't got any results. I will paste the output from my index
whenever I am testing the output I ain't getting any results...

When I am running
def time = doc['netflow.last_switched'].value;
return time;
I am getting output as:

please try the following

doc['netflow.last_switched'].value.millis - doc['netflow.first_switched'].value.millis

Thanks @matw

1 Like

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