My ultimate goal is to create a Kibana visualization that shows "How many days have passed since [today]". I was told I might be able to create an elasticsearch query that passes in a current_unix_time
or (new Date()).getTime()
or NOW()
or similar, then use Vega to draw a visualization for my dashboard.
I understand that I can NOT put in a unix time as part of my painless script.source
query (because if the distributed computing nature of an elastic cluster), but then someone told me to try to supply a current time as a script.params
. But I don't know the right syntax. Here's an example of what I tried:
GET myindex/_search
{
"runtime_mappings": {
"new_field": {
"type": "keyword",
"script": {
"source": "emit(params['now'])",
"params": {
"now": "(new Date()).getTime()"
}
}
}
},
"aggs":{
"new_field": {
"terms": {
"field": "new_field"
}
}
}
But the run time field just gives me the literal string (new Date()).getTime()
and not the actual time value. I've tried other things like changing the runtime field type, other possible functions/methods that I think might give me a time, but I still can't figure it out.
What am I doing wrong? What's the best way to work with a current_time
in a painless script? Or to plot visualizations that can do something like DATE_DIFF( docs['projectDueDate'].date , NOW() )
?