Hello Team,
could any one help me to write scripted field to get date difference in weeks between current datetime and doc['timestamp'].
to get current date time used datetime.new date().getTime()
Used this script.
(new Date().getTime()-doc['timestamp'].value)/7;
please give any other way if we have!
Refer error:
{
"root_cause": [
{
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"(new Date().getTime()-doc['timestamp'].value)/7",
" ^---- HERE"
],
"script": "(new Date().getTime()-doc['timestamp'].value)/7",
"lang": "painless",
"position": {
"offset": 38,
"start": 0,
"end": 47
}
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "kibana_sample_data_logs",
"node": "8mBwNeFOTrucFuoSsAwrog",
"reason": {
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"(new Date().getTime()-doc['timestamp'].value)/7",
" ^---- HERE"
],
"script": "(new Date().getTime()-doc['timestamp'].value)/7",
"lang": "painless",
"position": {
"offset": 38,
"start": 0,
"end": 47
},
"caused_by": {
"type": "class_cast_exception",
"reason": "Cannot apply [-] operation to types [java.lang.Long] and [org.elasticsearch.script.JodaCompatibleZonedDateTime]."
}
}
}
]
}
Thanks in advance.
Rakesh