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

**URL:** <https://discuss.elastic.co/t/calculate-the-hour-of-the-day-in-the-ingest-pipeline-display-error-message/224222>\
**Category:** Elasticsearch\
**Created:** [March 19, 2020, 6:58am UTC](https://discuss.elastic.co/t/calculate-the-hour-of-the-day-in-the-ingest-pipeline-display-error-message/224222 "2020-03-19T06:58:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![daniellienert](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/daniellienert/32/31435_2.png) [@daniellienert](https://discuss.elastic.co/u/daniellienert)\
**Post date:** [March 19, 2020, 6:58am UTC](https://discuss.elastic.co/t/calculate-the-hour-of-the-day-in-the-ingest-pipeline-display-error-message/224222/1 "2020-03-19T06:58:03Z")

</div>

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.

```auto
    {
      "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.

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [March 19, 2020, 3:15pm UTC](https://discuss.elastic.co/t/calculate-the-hour-of-the-day-in-the-ingest-pipeline-display-error-message/224222/2 "2020-03-19T15:15:13Z")

</div>

How about this?

```auto
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"
      }
    }
  ]
}

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 16, 2020, 3:15pm UTC](https://discuss.elastic.co/t/calculate-the-hour-of-the-day-in-the-ingest-pipeline-display-error-message/224222/3 "2020-04-16T15:15:14Z")

</div>

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