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:
doc['netflow.last_switched'].value-doc['netflow.first_switched'].value
but I am not getting any value while previewing result.
Specifications are as follows:
Type:Date
Format:Date

Hi Vikash

There are good examples in the painless documentation how to solve this:
https://www.elastic.co/guide/en/elasticsearch/painless/current/painless-datetime.html#_datetime_difference_elapsed_time
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
Screenshot_2019-09-03%20Discover%20-%20Kibana
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.