HI,
I'm having trouble calculating time diff (in seconds) between @timestamp and 'eventTime' date field using script field inside search query.
My mappings for 'eventTime' field is:
"mapping": { "dynamic": "false", "properties": { "eventTime": { "type": "date" } } }
and script field inside search query looks like this:
"script_fields": { "time_diff1": { "script": { "lang": "painless", "source": "(doc['@timestamp'].value.toInstant().toEpochMilli() - doc.eventTime.value.toInstant().toEpochMilli()) / 1000" } }
But I'm getting an error: "No field found for [@timestamp] in mapping with types "
"(doc['@timestamp'].value.toInstant().toEpochMilli() - doc.eventTime.value.toInstant().toEpochMilli()) / 1000",
" ^---- HERE"
My question is how to get this scripted field to work? Either by using painless or expression language. I've tried various approaches but with no luck.
Thanks in advance.