Calculate the hour of the day in the ingest pipeline / display error message

Hello there,

I am currently struggling with calculating the hour of the day from the timestamp of a log record using painless. The painless code (with adjusted field accessor) works as a scripted field.

Wether date_hour field nor the pipeline_failure_message is filled.
I appreciate any hint on how to debug this and at least get some error information. Or is there an easier way to do it?

I am using Elasticsearch 7.5.

    {
      "processors" : [
        {
          "script": {
            "lang": "painless",
            "source": "ZonedDateTime input = ctx._source['@timestamp']; DateTimeFormatter dtf = DateTimeFormatter.ofPattern('HH'); ctx.date_hour = input.format(dtf); ",
            "on_failure" : [
              {
                "set" : {
                  "field" : "pipeline_failure_message",
                  "value" : "{{ _ingest.on_failure_message }}"
                }
              }
            ]
          }
        }
      ]
    }

Thanks in advance.

How about this?

POST _ingest/pipeline/_simulate
{
  "pipeline": {
    "processors": [
      {
        "script": {
          "lang": "painless",
          "source": "def date = ZonedDateTime.parse(ctx['@timestamp']); ctx.hour_of_day = date.getHour();"
        }
      }
    ]
  },
  "docs": [
    {
      "_source": {
        "@timestamp": "2020-03-20T10:10:10.123Z"
      }
    }
  ]
}

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