Elasticsearch "mapper_parsing_exception" in CI
Elasticsearch could not parse a document field into the type declared in the index mapping. A string sent where a number or date is mapped, or a bad date format, produces mapper_parsing_exception on the index request. In CI this often surfaces because a fresh cluster inferred a mapping from the first document.
What this error means
An index or bulk request fails with "mapper_parsing_exception" and "failed to parse field [X] of type [Y]", naming the field and the expected type.
{"error":{"type":"mapper_parsing_exception","reason":"failed to parse field [age]
of type [long] in document with id '1'. ...","caused_by":{"type":"illegal_argument_exception",
"reason":"For input string: \"twenty\""}},"status":400}Common causes
A field value does not match the mapped type
The mapping declares (or inferred) a numeric or date type, but the document sends a value that cannot be parsed into it.
Dynamic mapping guessed the wrong type
On a fresh CI cluster the first indexed document sets the dynamic mapping; a later document with a different shape then fails to parse.
How to fix it
Define an explicit mapping before indexing
- Create the index with an explicit mapping instead of relying on dynamic inference.
- Match the field types to the data your tests actually index.
- Run this as a setup step so every run starts from the same mapping.
curl -X PUT "http://localhost:9200/products" -H 'Content-Type: application/json' -d '
{"mappings":{"properties":{"age":{"type":"integer"},"created":{"type":"date"}}}}'Send values that match the mapping
Fix the document so each field parses into its mapped type, for example a numeric age and an ISO-8601 date.
How to prevent it
- Create indices with explicit mappings in a CI setup step.
- Do not rely on dynamic mapping order, which depends on which document lands first.
- Validate fixture data against the mapping before indexing.