[7.5.1] script field issue on @timestamp

If it is a date type, I would expect some exceptions/errors related to type conversion / cast.

Using this script in my environment:

String datetime = doc['@timestamp'].value;
ZonedDateTime zdt = ZonedDateTime.parse(datetime);
String ret = zdt.format(DateTimeFormatter.ISO_INSTANT);
return ret;

throws a class_cast_exception with the following reason Cannot cast org.elasticsearch.script.JodaCompatibleZonedDateTime to java.lang.String

You can refer to our documentation that gives example on how to use a Datetime Input From an Indexed Document.

For example:

ZonedDateTime input = doc['@timestamp'].value;
String output = input.format(DateTimeFormatter.ISO_INSTANT);
return output;

I hope that helps.