# Mapping shows exception for leap year date

**URL:** https://discuss.elastic.co/t/mapping-shows-exception-for-leap-year-date/354439
**Category:** Elasticsearch
**Created:** [February 29, 2024, 11:48am UTC](https://discuss.elastic.co/t/mapping-shows-exception-for-leap-year-date/354439 "2024-02-29T11:48:37Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Siva\_Karan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/siva_karan/32/54688_2.png) [@Siva\_Karan](https://discuss.elastic.co/u/Siva_Karan)
#### Post date: [February 29, 2024, 11:48am UTC](https://discuss.elastic.co/t/mapping-shows-exception-for-leap-year-date/354439/1 "2024-02-29T11:48:37Z")

</div>

Hi Team,

Mapping "MM-dd" is throwing exception in leap year (feb 29,2024)

We have the below "MM-dd" format mapping and the system is checking of the year (1970) YYYY which is not a leap year and throwing the below exception

Mapping :  
"ao": {  
"type": "date",  
"format": "MM-dd"  
},  
"lo": {  
"type": "date",  
"format": "MM-dd"  
},

Exception :  
org.elasticsearch.index.mapper.MapperParsingException: failed to parse field [doj] of type [date] in document with id ''. Preview of field's value: '02-29'  
Caused by: org.elasticsearch.common.io.stream.NotSerializableExceptionWrapper: date\_time\_exception: Invalid date 'February 29' as '1970' is not a leap year

---

<div class="post-metadata">

### Author: ![Siva\_Karan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/siva_karan/32/54688_2.png) [@Siva\_Karan](https://discuss.elastic.co/u/Siva_Karan)
#### Post date: [February 29, 2024, 12:02pm UTC](https://discuss.elastic.co/t/mapping-shows-exception-for-leap-year-date/354439/2 "2024-02-29T12:02:53Z")

</div>

@stephenb Please help on this we have issue in our prod env.

---

<div class="post-metadata">

### Author: ![ahmed\_charafouddine](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ahmed_charafouddine/32/45129_2.png) [@ahmed\_charafouddine](https://discuss.elastic.co/u/ahmed_charafouddine)
#### Post date: [February 29, 2024, 12:55pm UTC](https://discuss.elastic.co/t/mapping-shows-exception-for-leap-year-date/354439/3 "2024-02-29T12:55:24Z")

</div>

Hello @Siva_Karan

Year in date format is required. So you can create for example a painless script which will complete this field by adding the current year by default and then generate a new field with the format YYYY-MM-dd

---

<div class="post-metadata">

### Author: ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)
#### Post date: [February 29, 2024, 1:00pm UTC](https://discuss.elastic.co/t/mapping-shows-exception-for-leap-year-date/354439/4 "2024-02-29T13:00:50Z")

</div>

I think I be also answered this here.

> [@"MM-dd" mapping is not working, throwing exception in leap year day (feb 29, 2024))](https://discuss.elastic.co/t/mm-dd-mapping-is-not-working-throwing-exception-in-leap-year-day-feb-29-2024/354436/1):
>
> Hi Team, We have the below mapping for saving the date of birth and date of joining with the below format ("MM-dd"), but the system is taking the year 1970 (not a leap year) and throwing the exception Mapping : "dob": { "type": "date", "format": "MM-dd" }, "doj": { "type": "date", "format": "MM-dd" }, Exception: [56]:ElasticSerachDAO:indexDocument:exception: org.elasticsearch.index.mapper.MapperParsingException: failed to parse field [doj] of type [date] in document with id '2240280…

There is no instant fix...

@ahmed_charafouddine Provided one approach.

You could create an ingest pipeline with code to set the current year.

What version are you using?

---

<div class="post-metadata">

### Author: ![Siva\_Karan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/siva_karan/32/54688_2.png) [@Siva\_Karan](https://discuss.elastic.co/u/Siva_Karan)
#### Post date: [February 29, 2024, 1:03pm UTC](https://discuss.elastic.co/t/mapping-shows-exception-for-leap-year-date/354439/5 "2024-02-29T13:03:01Z")

</div>

we are using 7.17.16 ES version

---

<div class="post-metadata">

### Author: ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)
#### Post date: [February 29, 2024, 1:10pm UTC](https://discuss.elastic.co/t/mapping-shows-exception-for-leap-year-date/354439/6 "2024-02-29T13:10:10Z")

</div>

How are you indexing your data?

You can't fix that field, you need to create a new field with the year in the mappings, like `YYYY-MM-dd`, then add the current year to your fields, like `2024-02-29`.

For example, you would need to add a new mapping like this:

```auto
PUT /your-index/_mapping
{
  "properties": {
    "dob_year": {
      "type": "date",
      "format": "YYYY-MM-dd"
    },
    "doj_year": {
      "type": "date",
      "format": "YYYY-MM-dd"
    }
  }
}

```

Then in your indexing process you need to add the value `2024` into the values of your `dob` and `doj` fields, and use those new fields in everything else.

You cannot index anything on the current fields if you use `02-29`.

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [February 29, 2024, 10:32pm UTC](https://discuss.elastic.co/t/mapping-shows-exception-for-leap-year-date/354439/7 "2024-02-29T22:32:49Z")

</div>

Please be patient in waiting for responses to your question and refrain from pinging multiple times asking for a response or opening multiple topics for the same question. This is a community forum, it may take time for someone to reply to your question. For more information please refer to the [Community Code of Conduct](https://www.elastic.co/community/codeofconduct) specifically the section "Be patient". Also, please refrain from pinging folks directly, this is a forum and anyone that participates might be able to assist you.

If you are in need of a service with an SLA that covers response times for questions then you may want to consider talking to us about a [subscription](https://www.elastic.co/subscriptions).

It's fine to answer on your own thread after 2 or 3 days (not including weekends) if you don't have an answer.

---

<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: [March 28, 2024, 10:32pm UTC](https://discuss.elastic.co/t/mapping-shows-exception-for-leap-year-date/354439/8 "2024-03-28T22:32:52Z")

</div>

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