Getting Current date in Painless

Hello,
I want to get the difference of current today and another date field as 'age' field.(new field)
So i was trying to add a dynamic script field in elastic search.Below is the query i used

curl -XPOST 'localhost:9200/test8/_search' -H 'Content-Type: application/json' -d '{
 "query": {
{


  "query": {
    "match_all": {}
  },
 "_source" : [],
  "script_fields": {
    "age1": {
      "script": "(Date().getTime()- doc['Request Date'].value)/(24*60*60*1000)"
    }
  }
}
}

But i get this error "Variable [DateTime] is not defined.
Seems like Date().getTime() cannot fetch the current date in painless
Could anyone let me know what is the syntax to get current date in painless.
I am using elastic search 7.6.0 and kibana 7.6.0
Thanks in advance

Please wrap your code with ``` so that it is readable.

Add index mapping and sample document so that we can replicate. Also add the expected result.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.