Scripted Field not working

Hi Folks,

I am trying to make a scripted field that takes the "@timestamp" field converts it to PST (pacific standard time) and then extracts the hour.

Can anyone see where I am going wrong with the below scripted field?

String datetime = doc['@timestamp'].value; 
ZonedDateTime utc = ZonedDateTime.parse(datetime);
ZonedDateTime pst = utc.withZoneSameInstant(ZoneId.of('America/Los_Angeles'));
return pst.getHour();

Hi

Here we go:

ZonedDateTime utc = doc['@timestamp'].value;
ZonedDateTime pst = utc.withZoneSameInstant(ZoneId.of('America/Los_Angeles'));
return pst.getHour();

You don't need to parse the value, it's already a ZonedDateTime
Best,
Matthias

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