Mapping shows exception for leap year date

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

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

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

I think I be also answered this here.

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?

3 Likes

we are using 7.17.16 ES version

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:

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.

1 Like

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 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.

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

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