@timestamp to ISO (Europe/Madrid)

Hi everyone!

So basically I have to parse my UTC timestamp in a set of Elasticsearch Watchers to ISO (Europe/Madrid).

IMPORTANT: I cannot use Logstash, quite unsure that use an Ingest Node for this would be permitted, so I may need an Elasticsearch Watcher code solution.

The main idea is to code it in a dynamic way, so I do not have to change the code every summer/winter-time. At this point anything that could be done at Watcher (JSON code) level would work for me.

Currently I'm using a transform as follows:
"transform": { "script": { "source": """def theDate = ctx.trigger.triggered_time.format(DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss Z")); return ['date': theDate, 'aggregations': ctx.payload.aggregations];""", "lang": "painless" } }

This is just a temporary patch, and I may need to display the local time directly.

Could you please give me a hand?

Thank you in advance!

I solve it through the following code:

  "transform": {
    "script": {
      "source": """def dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss z").withZone(ZoneId.of(ctx.metadata.timezone));
                   def theDate = ctx.trigger.triggered_time.format(dtf); 
                   return ['date': theDate, 'aggregations': ctx.payload.aggregations];""",
      "lang": "painless"

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