Groovy to painless

I'm strugling with this compilation code:

[esn1] failed to load/compile script [day]: {
  "type" : "script_exception",
   "reason" : "compile error",
   "caused_by" : {
     "type" : "illegal_argument_exception",
     "reason" : "invalid sequence of tokens near ['DateTime'].",
     "caused_by" : {
       "type" : "no_viable_alt_exception",
       "reason" : null
     }
   },
   "script_stack" : [
     "def opDate = new DateTime(doc[params.field ...",
     "                 ^---- HERE"
   ],
   "script" : "def opDate = new DateTime(doc[params.field].date);opDate.getDayOfMonth();",
   "lang" : "painless"
 }

I'm trying to translate a groovy script to painless script. I'm trying to get day of a month of a date.

My groovy script is:

def opDate = new DateTime(doc[params.field].date);opDate.getDayOfMonth();

How could I "translate" it?

Thanks.

Hi @living_jordi,

can you try this?

Instant.ofEpochMilli(doc['field'].value).atZone(ZoneId.systemDefault()).getDayOfMonth()

Daniel

Hi @danielmitterdorfer,

Thanks for your answer. It looks like well.

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