Kibana painless- Difference in dates in days

You could do something like the following:

return (doc['date2'].value.millis - doc['date1'].value.millis) / 1000 / 60 / 60 / 24;