# Extract year from date field and assign to new field

**URL:** <https://discuss.elastic.co/t/extract-year-from-date-field-and-assign-to-new-field/204691>\
**Category:** Elasticsearch\
**Created:** [October 22, 2019, 4:18pm UTC](https://discuss.elastic.co/t/extract-year-from-date-field-and-assign-to-new-field/204691 "2019-10-22T16:18:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![manideep](https://avatars.discourse-cdn.com/v4/letter/m/6a8cbe/32.png) [@manideep](https://discuss.elastic.co/u/manideep)\
**Post date:** [October 22, 2019, 4:18pm UTC](https://discuss.elastic.co/t/extract-year-from-date-field-and-assign-to-new-field/204691/1 "2019-10-22T16:18:51Z")

</div>

Hi All,

is there a way to extract year from date field and assign to new field?

I want to update existing mapping with new field or i can re-index with new new mapping as well.

Please suggest.

---

<div class="post-metadata">

**Author:** ![Glen\_Smith](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/glen_smith/32/111656_2.png) [@Glen\_Smith](https://discuss.elastic.co/u/Glen_Smith)\
**Post date:** [October 23, 2019, 2:23am UTC](https://discuss.elastic.co/t/extract-year-from-date-field-and-assign-to-new-field/204691/2 "2019-10-23T02:23:19Z")

</div>

Manideep,

First, I infer that you already have these documents indexed, and that the optimal solution would let you reprocess them right in the cluster.

Yes, you can do this using an [Ingest Pipeline](https://www.elastic.co/guide/en/elasticsearch/reference/current/ingest.html).

Assuming your existing date field is in some consistent, structured form, I think the key for what you describe will be the [Grok Processor](https://www.elastic.co/guide/en/elasticsearch/reference/current/grok-processor.html). You'll define a pattern that captures the year from the existing field and maps it to a new field.

Of course this pipeline will also work with new documents that you index.

---

<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:** [November 20, 2019, 2:23am UTC](https://discuss.elastic.co/t/extract-year-from-date-field-and-assign-to-new-field/204691/3 "2019-11-20T02:23:24Z")

</div>

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