Watcher transform runtime error illegal_argument_exception: "dynamic method [java.lang.String, getMillis/0] not found"

Hi, I've created a watch containing transform for which I get a runtime error when executing:

        "type" : "illegal_argument_exception",
        "reason" : "dynamic method [java.lang.String, getMillis/0] not found"
       "script_stack" : [
        "tmpdate = Instant.ofEpochMilli(ctx.payload.hits.hits[j]._source.eventTime.getMillis()).atZone(ZoneId.of('Europe/Zagreb')).format(DateTimeFormatter.ofPattern('YYYY-MM-dd HH:mm:ss')); ",
        "                                                                         ^---- HERE"
      ],

The whole transform is here (I've break the lines for easier readibility):

  "transform":{
      "script": {
		"suorce": "
			ctx.payload.transform = []; 
			def document = []; 
			for (int j=0;j<ctx.payload.hits.hits;j++)
			{
				def tmpdate = Instant.ofEpochMilli(ctx.payload.hits.hits[j]._source.eventTime.getMillis()).atZone(ZoneId.of('Europe/Zagreb')).format(DateTimeFormatter.ofPattern('YYYY-MM-dd HH:mm:ss'));; 
				document = [
					'amount': ctx.payload.hits.hits[j]._source.amount, 
					'eventTime': tmpdate
				]; 
				ctx.payload.transform.add(document) 
			} 
			return ['totalCnt': ctx.payload.hits.total, 'transformedHits': ctx.payload.transform];",
          "lang": "painless"
      }
  }

Any help to get me on the right line is appreciated.

EDIT:
Maping for field eventTime is:

"eventTime": { "type": "date" }

EDIT2:
Watcher executes and returns this document inside hits:

      "hits" : {
        "hits" : [
          {
            "_index" : "my_requests",
            "_type" : "_doc",
            "_source" : {
              "amount" : 1200.0,
              "eventTime" : "2019-07-23T12:40:26.9739999Z",
              "@version" : "1",
              "status" : "0"
            },
            "_id" : "bb64b6af3c374cfb9ae2ec107ec2310d",
            "sort" : [
              1563885626973
            ],
            "_score" : null
          }, ...

OK, to answer my own question, this error is obviously stating that I'm trying to do a datetime function on a string object (even my field is mapped as date ???) so I've done the following in order to get the date field from UTC to local time:

def tmpdate = ZonedDateTime.parse(ctx.payload.hits.hits[j]._source.eventTime).withZoneSameInstant(ZoneId.of('Europe/Zagreb')).format(DateTimeFormatter.ofPattern('YYYY-MM-dd HH:mm:ss'));

accessing the source will only return JSON data structures like string/bool/integer, but not parse to a date. This only happens when doc values are used (i.e. for sorting or for script fields).

hope this helps!

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