Painless script to get date difference

It sounds like at least one of your fields is a date, not a number. If a field shows up as date type in your mapping, you have to access the value with doc['myFieldNameHere'].value.millis to get the timestamp value as a number.

Also see here Kibana painless- Difference in dates in days