# MapperParsingException: failed to parse field [created_at] of type [date] in document with id 'doc123'. Preview of field's value: '2024-13-01'

- **ID:** `elasticsearch/mapping-conflict-on-date-format`
- **Domain:** elasticsearch
- **Category:** data_error
- **Verification:** ai_generated
- **Fix Rate:** 90%

## Root Cause

The field value does not match the expected date format defined in the mapping, such as an invalid month or a mismatched timestamp pattern.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| elasticsearch 7.17 | active | — | — |
| elasticsearch 8.11 | active | — | — |
| elasticsearch 8.12 | active | — | — |

## Workarounds

1. **Update the index mapping to accept multiple date formats: PUT /my_index/_mapping { "properties": { "created_at": { "type": "date", "format": "yyyy-MM-dd||yyyy/MM/dd||epoch_millis" } } }** (90% success)
   ```
   Update the index mapping to accept multiple date formats: PUT /my_index/_mapping { "properties": { "created_at": { "type": "date", "format": "yyyy-MM-dd||yyyy/MM/dd||epoch_millis" } } }
   ```
2. **Use an ingest pipeline to preprocess the date field before indexing: PUT _ingest/pipeline/date_fix { "description": "Fix date format", "processors": [ { "date": { "field": "created_at", "target_field": "created_at", "formats": [ "yyyy-MM-dd" ], "timezone": "UTC", "locale": "en" } } ] }** (85% success)
   ```
   Use an ingest pipeline to preprocess the date field before indexing: PUT _ingest/pipeline/date_fix { "description": "Fix date format", "processors": [ { "date": { "field": "created_at", "target_field": "created_at", "formats": [ "yyyy-MM-dd" ], "timezone": "UTC", "locale": "en" } } ] }
   ```
3. **Reindex the data with a script to transform the date: POST _reindex { "source": { "index": "my_index" }, "dest": { "index": "my_index_new" }, "script": { "source": "if (ctx._source.created_at == '2024-13-01') { ctx._source.created_at = '2024-01-01' }" } }** (80% success)
   ```
   Reindex the data with a script to transform the date: POST _reindex { "source": { "index": "my_index" }, "dest": { "index": "my_index_new" }, "script": { "source": "if (ctx._source.created_at == '2024-13-01') { ctx._source.created_at = '2024-01-01' }" } }
   ```

## Dead Ends

- **** — Converting date to text loses date-related query capabilities (e.g., range queries, date histograms) and may break existing queries. (70% fail)
- **** — This only masks the issue; malformed dates are stored as null, leading to data loss and unexpected query results. (60% fail)
- **** — If the incoming data uses a different format (e.g., 'yyyy/MM/dd'), it will still fail after re-creation. (65% fail)
