Are your field strings or date types?
You can look at the index pattern to see. For example my date1 and date2 are dates (they're also scriptable and aggregatable which I think they need to be if you use them in a scripted field);
Then I created this scripted field (the difference in dates is in milliseconds so I divide by 1000 to get seconds, by 60 to get minutes, by 60 to get hours, by 24 to get days);
(doc['date2'].value - doc['date1'].value) / 1000 / 60/ 60 /24
And the result is 10;
If you'r dates are strings, I'll have to find the trick to convert them and then I expect it would be the same formula.