Edited this heavily to be information about dates and format, hopefully useful to someone in the future:
The listed value of a date is something like 1.568084083246E12
(Java will convert doubles to strings with Scientific Notation)
Someone on ES irc suggested this was Decimal Format which seems to line up with what the documentation states:
Internally, dates are converted to UTC (if the time-zone is specified) and stored as a long number representing milliseconds-since-the-epoch.
Looking at a sample result query,
"lastDocument" : {
"value" : 1.568084083246E12,
"value_as_string" : "2019-09-10T02:54:43.246Z"
},
"firstDocument" : {
"value" : 1.568073644243E12,
"value_as_string" : "2019-09-10T00:00:44.243Z"
},
"timeSpent" : {
"value" : 1.0439003E7,
},
So if timespent is a long of milliseconds... That means it's 10439003
milliseconds, aka 10439
seconds, which converts to 2 hours, 53 minutes and 59 seconds.
Finally, I updated my bucket_script aggregation, including a 'format' parameter, which delivers to me just the seconds value, which is simpler for post processing:
"lastDocument" : {
"max" : { "field" : "@timestamp" }
},
"firstDocument" : {
"min" : { "field" : "@timestamp" }
},
"timeSpent" : {
"bucket_script": {
"buckets_path": {
"firstDocument": "firstDocument",
"lastDocument": "lastDocument"
},
"script": "(params.lastDocument - params.firstDocument) / 1000",
"format": "0"
}
},
Which outputs nicely:
"timeSpent" : {
"value" : 10439.003,
"value_as_string" : "10439"
},