# Watcher transform runtime error illegal\_argument\_exception: "dynamic method \[java.lang.String, getMillis/0\] not found"

**URL:** <https://discuss.elastic.co/t/watcher-transform-runtime-error-illegal-argument-exception-dynamic-method-java-lang-string-getmillis-0-not-found/191774>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [July 23, 2019, 9:17am UTC](https://discuss.elastic.co/t/watcher-transform-runtime-error-illegal-argument-exception-dynamic-method-java-lang-string-getmillis-0-not-found/191774 "2019-07-23T09:17:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Josip\_Cagalj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/josip_cagalj/32/42899_2.png) [@Josip\_Cagalj](https://discuss.elastic.co/u/Josip_Cagalj)\
**Post date:** [July 23, 2019, 9:17am UTC](https://discuss.elastic.co/t/watcher-transform-runtime-error-illegal-argument-exception-dynamic-method-java-lang-string-getmillis-0-not-found/191774/1 "2019-07-23T09:17:52Z")

</div>

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
> }, ...
> 
> ```

---

<div class="post-metadata">

**Author:** ![Josip\_Cagalj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/josip_cagalj/32/42899_2.png) [@Josip\_Cagalj](https://discuss.elastic.co/u/Josip_Cagalj)\
**Post date:** [July 24, 2019, 7:34am UTC](https://discuss.elastic.co/t/watcher-transform-runtime-error-illegal-argument-exception-dynamic-method-java-lang-string-getmillis-0-not-found/191774/2 "2019-07-24T07:34:43Z")

</div>

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'));

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [August 1, 2019, 12:03pm UTC](https://discuss.elastic.co/t/watcher-transform-runtime-error-illegal-argument-exception-dynamic-method-java-lang-string-getmillis-0-not-found/191774/3 "2019-08-01T12:03:32Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 29, 2019, 12:03pm UTC](https://discuss.elastic.co/t/watcher-transform-runtime-error-illegal-argument-exception-dynamic-method-java-lang-string-getmillis-0-not-found/191774/4 "2019-08-29T12:03:35Z")

</div>

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