Add weekend field via ingest pipeline

Hey Jason,

When asking a question on this forum, please format any code with the </> button, as explained here. It makes it much easier to read. :slight_smile:

Your script has several issues, the most important of which is that you're using the doc['field'] notation to access field values. That notation only works at query and aggregation time. At index time, you need to access fields with the ctx.field notation.

The following pipeline should work:

PUT _ingest/pipeline/addWeek
{
  "description": "check weekend by using alrm_occr_ddt.date.dayOfWeek",
  "version": 1,
  "processors": [
    {
      "pipeline": {
        "if": "def dayOfWeek = OffsetDateTime.parse(ctx.alrm_occr_ddt).getDayOfWeek(); return (dayOfWeek == DayOfWeek.SATURDAY || dayOfWeek == DayOfWeek.SUNDAY)",
        "name": "weekend_true"
      }
    }
  ]
}
1 Like