date.toString() doesn't work after upgrading to ES 8.3

After updating the ES to the newest version some of my runtime fields stop working, basically, the date.toString() doesn't work anymore to convert a date to a string.

Is there any option for this? I have been searching for hours in the release notes and I couldn't find anything regarding this.

This is my code:

{
 "runtime": {
   "dateAsString": {
     "type": "keyword",
     "script": """if (doc['date'].empty) {
     					emit('');
     				} else {
                emit(doc['date'].value.toString('dd-MM-yyyy')); // this field is broken
              }"""
   },
   "milage": {
     "type": "keyword",
     "script": """if (doc['end.odometer'].empty) {
     					emit('-');
     				} else {
                emit(doc['end.odometer'].value.toString()); // this one works perfectly
              }"""
   }
 }
}

The dashboards and indexes using the field dateAsString are all broken, by doing some debug I kno for a fact that .toString() works for the milage field.

Finally got it working, if anyone else got the same issue, this is how I solved it:

"script": """if (doc['date'].empty) {
     					emit('');
     				} else {
     				    DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");
                        DateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm");
                        Date date = inputFormat.parse(doc['date'].value.toString());
                        emit(formatter.format(date));
              }"""
   },

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