# Add weekend field via ingest pipeline

**URL:** <https://discuss.elastic.co/t/add-weekend-field-via-ingest-pipeline/177039>\
**Category:** Elasticsearch\
**Created:** [April 16, 2019, 9:13am UTC](https://discuss.elastic.co/t/add-weekend-field-via-ingest-pipeline/177039 "2019-04-16T09:13:24Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![abdon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdon/32/9195_2.png) [@abdon](https://discuss.elastic.co/u/abdon)\
**Post date:** [April 16, 2019, 9:49am UTC](https://discuss.elastic.co/t/add-weekend-field-via-ingest-pipeline/177039/2 "2019-04-16T09:49:36Z")

</div>

Hey Jason,

When asking a question on this forum, please format any code with the `</>` button, as explained [here](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It makes it much easier to read. 🙂

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:

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

```

---

_[View the full topic](https://discuss.elastic.co/t/add-weekend-field-via-ingest-pipeline/177039)._
