How to convert string to date using kibana painless script


(Mouli) #1

I have string fields in my index like
"repliedTs": "2018-12-27T10:58:28.423-05:00",
"receivedTs": "2018-12-27T10:58:27.168-05:00"
i am trying to write kibana painless script to convert string type to date and find the difference, but could not get success. could please help me
here is my code...
(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S").parse(doc['repliedTs'].value).getTime()) - (new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S").parse(doc['receivedTs'].value).getTime())


(Jen Huang) #2

These fields would be dynamically mapped to date type by ES. Try:

doc['repliedTs'].value.millis - doc['receivedTs'].value.millis

This will retrieve the difference in milliseconds.


(Mouli) #3

Thanks for reply jen-Huang,
I tried as you suggested but not working
doc['repliedTs'].value.millis - doc['receivedTs'].value.millis
Is there any other way to convert string to date?