Get the date right now

hello,
i have filed lastDate i whant to make script filed to calcul the diffrence of the value of lasteDate and the actual date
there is way to get actual date in kibana ?

thank's

By "actual date" I think you're talking about the date right now.

Scripted fields in Kibana simply use Elasticsearch's Painless scripting language. Unfortunately, that language can only be used to work with numbers, booleans, voids, and arrays. Since there is no way to operate on dates in the language, there is no way to calculate the difference between dates in scripted fields.

1 Like

Ah, Painless doesn't support dates, but the expression syntax does. It's not clear to me how you'd get the current date to do the calculation with though.

Thank you for your return. I used groovy to calculate the current date. and it's working good

Mind sharing how you got the current date in the Groovy script? I couldn't find an example that did that, and it would be useful to know what that looks like.

this is my script_fields i called current data with "DateTime.now().getMillis()"

and i used it to compare with my session date

"script_fields" : {
      "Checks" : {
          "script" : {
         "lang": "groovy",
          "inline":
         "doc['sessionDate'].collect{ if (it!=0){ 
         if (((DateTime.now().getMillis()-it)/(1000*60*60*24))<60) 
         'check ok';else  'check no';   }else 'Never check'; }"
      }
    }
}
1 Like

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