Scrivio Interview library
DebuggingIntermediate7 min read · updated 12 November 2026

Elasticsearch rejects many log events with mapping errors: 'mapper_parsing_exception: failed to parse field [user] of type [keyword]'. Some services log user as a string and others as an object. How do you fix this and prevent it?

Elasticsearch's dynamic mapping fixed the type of the user field from the first document it saw, a string mapped as keyword, so every later document where user is an object fails with mapper_parsing_exception and is rejected. We fix it by agreeing a common schema such as Elastic Common Schema, where user is always an object with user.name and user.id, enforced in the shared logging configuration, by index templates with explicit mappings and dynamic mapping off or unknown fields under a flattened field, and by normalising old formats in an ingest pipeline. Rejected events should be monitored and sent to a dead letter queue, and limiting dynamic fields also prevents mapping explosion.

Why this question is asked

Mapping errors are one of the most frustrating problems in a shared logging cluster, because they are silent from the application's point of view: the service logs normally, but its events never appear in Kibana, often exactly the events someone needs during an incident. They are also a sign of a deeper issue, that many teams write into the same indices with no agreed schema. Interviewers ask this to see whether we understand how Elasticsearch decides field types and how to make the cluster robust. In this answer, we will recap mappings, reproduce the error, fix the schema, enforce it with templates, handle old data and rejected events, and look at mapping explosion.

1A Quick Recap of Mappings

A mapping is the schema of an Elasticsearch index: for each field, its type, such as keyword for exact values, text for full-text search, date, long or object for nested fields. Once a field has a type in an index, it cannot change in that index, because the data on disk is stored according to that type.

With dynamic mapping, Elasticsearch creates the mapping on the fly. When a document arrives with a field it has not seen, it guesses a type from the value and adds it to the mapping. This is convenient and is the default, but it means the first document to use a field name decides its type for everyone writing to that index.

2Reproducing the Error

Two services write to the same log index. Service A logs the user as a plain string. Service B logs it as an object. Whichever arrives first after the index is created wins.

Java
// First document of the day, from service A
POST logs-app/_doc
{ "@timestamp": "2026-11-06T08:00:01Z", "message": "login", "user": "alice" }
// -> 201 Created; mapping now has user: keyword
// Later, from service B
POST logs-app/_doc
{ "@timestamp": "2026-11-06T08:00:05Z", "message": "order placed", "user": { "id": "u-17", "tier": "gold" } }
// -> 400 mapper_parsing_exception: failed to parse field [user] of type [keyword]

Notice that the outcome depends on order. If service B had written first, user would be an object, and service A's documents would fail instead with an error that an object mapping found a concrete value. That is why the problem seems to come and go, often changing with each daily index or rollover: it depends on which service logged first.

3Fix 1: Agree a Common Schema

The root cause is that two teams use the same field name for different things. The lasting fix is one schema for everyone. Elastic Common Schema, ECS, already defines user as an object with fields such as user.name, user.id and user.email, along with service.name, trace.id, log.level and many others. Adopting it saves a long debate and matches what Kibana's built-in views expect.

We enforce it where logs are produced. The shared Spring Boot logging configuration uses structured logging in ECS format, and teams add their own fields only through the MDC or structured arguments under agreed names. Non-Java services use ECS libraries for their language. A field that does not fit the schema goes under a team-specific namespace rather than taking a common name like user.

4Fix 2: Index Templates With Explicit Mappings

Next we stop relying on dynamic mapping for important fields. An index template applies settings and mappings to every new index or data stream that matches a pattern, so each day's or each rollover's index gets the same, explicit schema. We map the known fields explicitly and set dynamic to false, so unknown fields are kept in the stored document but not indexed, which means they cannot break or bloat the mapping. For teams that need ad hoc searchable fields, we give them a flattened field, which stores a whole object of arbitrary keys as one field.

YAML
PUT _index_template/logs-app
{
"index_patterns": ["logs-app-*"],
"data_stream": {},
"priority": 500,
"template": {
"settings": { "index.default_pipeline": "logs-app-normalise" },
"mappings": {
"dynamic": false,
"properties": {
"@timestamp": { "type": "date" },
"message": { "type": "text" },
"log": { "properties": { "level": { "type": "keyword" } } },
"service": { "properties": { "name": { "type": "keyword" } } },
"trace": { "properties": { "id": { "type": "keyword" } } },
"user": { "properties": { "id": { "type": "keyword" }, "name": { "type": "keyword" } } },
"labels": { "type": "flattened" }
}
}
}
}

Remember that a template applies only to new indices. The current index keeps its broken mapping, so after creating the template we roll the data stream over, and the next backing index gets the right one. For stricter control, dynamic set to strict rejects any document with an unknown field, which is useful in audit indices but usually too harsh for application logs.

5Fix 3: Normalise Old Formats and Catch Rejected Events

Teams will not all migrate on the same day. An ingest pipeline, a set of processors Elasticsearch runs before indexing, can convert the old shape to the new one, so service A's string becomes user.name. The template above makes it the default pipeline for the index.

Java
PUT _ingest/pipeline/logs-app-normalise
{
"processors": [
{ "script": {
"source": "if (ctx.user instanceof String) { ctx.user = ['name': ctx.user]; }"
} }
]
}
// "user": "alice" -> "user": { "name": "alice" }
Step throughWhat happens to a log event now
  1. Event arrivesFrom any service, old or new format
  2. Ingest pipelineNormalise user string to user.name
  3. Fits the explicit mapping?
    YesIndexed and searchableNoRejected
  4. Dead letter queue or failure storeKept, counted per service
  5. Alert on rejection rateOwning team fixes the format

5 steps in order. Play them, or step through them one at a time.

No event is lost silently, and the schema is enforced at three points.

And we stop losing events silently. If Logstash ships the logs, its dead letter queue, enabled with dead_letter_queue.enable: true, keeps documents that Elasticsearch rejected with mapping errors so they can be inspected and replayed after a fix. Newer Elasticsearch versions also offer a failure store for data streams that keeps rejected documents inside the cluster; check whether your version supports it. Either way, we alert on the rate of rejected events per service, so a mapping conflict becomes a ticket the same day instead of a gap discovered during an incident.

6Mapping Explosion

The same weakness causes a second problem. With dynamic mapping, every new field name becomes a new mapping entry. A service that logs a map with ids as keys, such as {"orders": {"A-1093": 1, "A-1094": 2}}, creates a new field for every order. The mapping grows until it hits index.mapping.total_fields.limit, 1,000 by default, after which documents with new fields are rejected, and before that the large cluster state slows down every node and can make the cluster unstable.

Explicit mappings with dynamic set to false, flattened fields for free-form data, and the shared schema solve both problems at once. A periodic check of the field count per index catches services that start creating fields again.

7Follow-up questions

Can we just change the type of the user field in the existing index?

No. A field's type cannot be changed in place, because the indexed data is stored in that type. We either let the current index age out after rolling over to a new one with the right template, or reindex the data into a new index with the correct mapping if we need it.

Why not set user to a flattened type and accept both shapes?

A flattened field accepts objects with any keys, but a plain string at that path is still not an object, so it does not solve mixed types by itself. It also makes all values keywords, losing proper types. It is a good home for unknown team fields, not for core fields that should be in the schema.

8Conclusion

In this answer, we saw that dynamic mapping fixes a field's type from the first document, so when one service logs user as a string and another as an object, whichever comes second is rejected with mapper_parsing_exception. We fixed it by agreeing a common schema such as ECS and enforcing it in the shared logging configuration, by index templates with explicit mappings, dynamic mapping off and a flattened field for unknown data, and by an ingest pipeline that normalises old formats. We stopped losing events silently with a dead letter queue or failure store and alerts, and the same measures prevent mapping explosion.

What to say in the interviewAbout 90 seconds aloud

Open with

The cause is dynamic mapping. When an index is created, the first document that contains user decides its type, here a string, so it became a keyword, and any later document where user is an object is rejected with mapper_parsing_exception.

Then, if they want more

It flips with every new daily index or rollover depending on which service logs first, and the events are silently lost.

I'd fix it at the root by agreeing a common schema, ideally Elastic Common Schema, where user is always an object with user.name and user.id, and enforce it through the shared logging configuration, for Spring Boot structured logging in ECS format.

Then I'd stop relying on dynamic mapping: an index template with explicit mappings for the known fields, dynamic set to false so unknown fields are stored but not indexed, and a flattened field for team-specific extras. Because templates only apply to new indices, I'd roll the data stream over.

For services that haven't migrated, an ingest pipeline converts a string user into user.name. And I'd make rejections visible: Logstash's dead letter queue or the data stream failure store if the version has it, plus an alert on rejected events per service.

The same measures prevent mapping explosion, where unbounded field names hit the total fields limit and make the cluster unstable.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Elasticsearch rejects many log events with mapping errors: 'mapper_parsing_exception...": https://scrivio-interview-library.netlify.app/spring-boot/observability/c7ab3bbdcf/