Scrivio Interview library
ScenarioIntermediate7 min read · updated 12 November 2026

A logging index has over 10,000 fields because services send arbitrary JSON keys, and the cluster rejects writes with 'Limit of total fields [1000] has been exceeded'. How do you fix it properly?

Dynamic mapping creates a new field for every new JSON key, so services sending arbitrary keys cause a mapping explosion that bloats the cluster state and eventually hits index.mapping.total_fields.limit, 1,000 by default. Raising the limit only delays the problem; the proper fix is to stop arbitrary keys from becoming fields, with dynamic: false or strict at the right level of the mapping, or the flattened type in Elasticsearch (flat_object in OpenSearch) for free-form key-value data. Then we agree a logging schema such as ECS with the teams, validate it in the log pipeline, and put the corrected mapping in index templates so every new index gets it.

Why this question is asked

Logging indices are where mapping explosions usually happen, because many services send whatever JSON they like and dynamic mapping turns every key into a field. One day ingestion fails, logs stop arriving exactly when someone needs them, and the quick fix of raising a limit makes the cluster slower for everyone. Interviewers ask this scenario to see whether we understand why the limit exists and how to fix the cause rather than the symptom. In this answer, we will see how the explosion happens and why it hurts the whole cluster, why raising the limit is not a fix, how to control dynamic mapping, how flattened fields work, and how to make the fix stick with a schema, pipeline validation and templates.

1How a Mapping Explodes

With dynamic mapping, Elasticsearch and OpenSearch add a field to the index mapping the first time they see a new key. That is convenient for a few stable keys. Logging breaks it, because keys are often data, not schema: a service logs {"user_123": "ok"} or {"headers": {"x-request-id-5f2a": ...}}, and every new user id or header name becomes a new field.

Java
POST /logs-2026.11.06/_doc
{ "service": "cart", "ctx": { "sku_88121": 2, "sku_90410": 1 } }
// mapping now has ctx.sku_88121 and ctx.sku_90410 (long)
// thousands of documents later
// 400 illegal_argument_exception:
// Limit of total fields [1000] has been exceeded while adding new fields [3]

Each field also costs more than one entry: a string becomes text plus a .keyword subfield, and object levels count too. So 400 distinct string keys already reach 800 fields. The rejected documents are the ones carrying new keys, but in practice that soon means most documents from the noisy services.

2Why the Limit Exists

The mapping is part of the cluster state, a structure that the elected master node maintains and publishes to every node in the cluster. Every new field changes the mapping, which means a cluster state update that the master must compute and every node must apply. With thousands of indices and tens of thousands of fields, these updates become large and frequent, the master gets slow, and unrelated operations such as creating indices or moving shards queue behind them.

Each field also costs memory and disk on the data nodes, for its index structures and doc values, and queries that expand over many fields get slower. The total fields limit, 1,000 per index by default, is a safety valve that stops one index from degrading the whole cluster.

3Why Raising the Limit Only Delays It

The tempting fix is one setting change.

Java
PUT /logs-*/_settings
{ "index.mapping.total_fields.limit": 20000 }
// writes succeed again ... until the keys reach 20,000

It works for a few days or weeks, because the source of new keys has not changed. Meanwhile the cluster state grows, the master slows down, and the indices become harder to query and visualise, since tools like Kibana list every field. With over 10,000 fields already, this index is past the point where a higher limit is reasonable. Raising it slightly can be an emergency measure to restore ingestion while the real fix is deployed, but only together with that fix. Some recent Elasticsearch versions also offer index.mapping.total_fields.ignore_dynamic_beyond_limit, which keeps accepting documents and stops mapping new fields once the limit is reached (check your version).

4Controlling Dynamic Mapping at the Right Level

The dynamic setting can be set for the whole mapping or for any object within it. true adds new fields; false keeps unknown fields in _source but does not index or map them; strict rejects documents with unknown fields; and runtime maps them as runtime fields, computed at query time (Elasticsearch). For logs, a good shape is a strict or explicit top level for the standard fields, and dynamic: false on the free-form object, so arbitrary keys are stored but never become fields.

YAML
PUT /_index_template/logs
{
"index_patterns": ["logs-*"],
"template": { "mappings": {
"dynamic": "strict",
"properties": {
"@timestamp": { "type": "date" },
"service": { "properties": { "name": { "type": "keyword" } } },
"log": { "properties": { "level": { "type": "keyword" } } },
"message": { "type": "text" },
"trace": { "properties": { "id": { "type": "keyword" } } },
"labels": { "type": "flattened" },
"ctx": { "type": "object", "dynamic": false }
} } },
"priority": 200
}
// ctx.sku_88121 is kept in _source, not mapped: field count stays fixed

Notice the choice per level. With strict at the top, a service that invents a new top-level key gets its document rejected, which surfaces the problem quickly; some teams prefer false at the top too so no log is ever lost, and alert on unknown keys in the pipeline instead.

5Using Flattened Fields for Free-Form Data

dynamic: false means the arbitrary keys are not searchable at all. When teams do need to filter on them, the flattened type in Elasticsearch, or flat_object in OpenSearch, is the answer. It maps a whole object as one field: all its leaf values are indexed as keywords, and they can be queried by full path, such as labels.customer_tier: gold, without adding a field per key.

Java
POST /logs-2026.11.07/_doc
{ "@timestamp": "2026-11-07T09:00:00Z", "service": { "name": "cart" },
"labels": { "customer_tier": "gold", "experiment_17": "B" } }
GET /logs-*/_search
{ "query": { "term": { "labels.customer_tier": "gold" } } }
// matches, and the mapping still has a single field: labels
Options for unknown keys
ApproachField countSearchable?When to use
dynamic: true (default)grows without limityes, typednever for arbitrary keys
raise total_fields.limitgrows, later failureyesemergency only, with a real fix
dynamic: false on the objectfixedno, kept in _sourcecontext rarely queried
dynamic: strictfixedrejects the documenttop level of a governed schema
flattened / flat_objectone fieldyes, as keywordslabels and free-form key-values

The trade-off is that every value is treated as a keyword: no full-text analysis and no numeric ranges in the usual sense, since numbers are compared as strings. That is acceptable for labels and context, and it is exactly what free-form key-value data needs.

6Making the Fix Stick

The mapping change protects the cluster; agreement with the teams prevents the next explosion. I would adopt a common logging schema, such as the Elastic Common Schema (ECS), which defines standard names like @timestamp, service.name, log.level and trace.id, and ask services to put anything else under labels or a context object. The log pipeline, for example an ingest pipeline, Logstash or a collector such as the OpenTelemetry Collector, validates documents against that schema, renames known variants, moves unknown top-level keys under the context object and counts violations per service, so owners can see and fix them.

Finally, the corrected mapping must live in an index template, like the one above, because logging uses a new index per day or a data stream with rollover. A mapping change applied only to today's index would vanish at midnight. Existing exploded indices can be left to age out under the retention policy, or reindexed if they must stay searchable for long.

7Follow-up questions

Does dynamic: false lose data?

No. The original JSON stays in _source and is returned with the document; the unknown keys are just not indexed, so we cannot search or aggregate on them. If they become important, we can add a mapping for them and reindex or use runtime fields.

What about the depth and nested limits?

There are related limits such as index.mapping.depth.limit and index.mapping.nested_fields.limit. They protect against the same kind of growth and should also be left at sensible values rather than raised to make errors disappear.

How do we find which services send the most new keys?

Compare the mapping's field names with the service.name values of documents carrying them, or count unknown keys per service in the pipeline. Usually one or two services cause most of the growth.

8Conclusion

In this answer, we saw that dynamic mapping turns every new JSON key into a field, which bloats the cluster state the master must publish to every node until the 1,000-field limit rejects writes. Raising the limit only postpones the failure. The real fix is dynamic: false or strict at the right level, the flattened or flat_object type for free-form key-value data, a shared schema such as ECS validated in the log pipeline, and index templates so every new index starts with the corrected mapping.

What to say in the interviewAbout 90 seconds aloud

Open with

The root cause is dynamic mapping: every new JSON key creates a new field, and when services log keys that are really data, like user ids or SKUs, the mapping explodes.

Then, if they want more

That hurts the whole cluster because the mapping is part of the cluster state, which the master has to update and publish to every node, and each field costs memory and makes queries and tools slower.

The 1,000 total fields limit exists to stop that, so raising index.mapping.total_fields.limit only delays the failure, and I would only do it briefly to restore ingestion while deploying the real fix.

The real fix is controlling dynamic mapping at the right level: define the standard fields explicitly, use strict or false at the top level, and set dynamic false on the free-form context object so arbitrary keys stay in _source but never become fields.

Where teams need to filter on free-form keys, I would use the flattened type in Elasticsearch, or flat_object in OpenSearch, which indexes the whole object as a single field with keyword values queryable by path.

Then I would agree a logging schema such as ECS with the teams, with standard names and a labels object for extras, and validate it in the log pipeline, moving or counting unknown keys per service. Finally, the mapping goes into an index template, because daily indices or data streams would otherwise lose the fix at the next rollover.

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.
Official documentation
Elasticsearch documentation
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 "A logging index has over 10,000 fields because services send arbitrary JSON keys, and...": https://scrivio-interview-library.netlify.app/databases/search-engines/44ae0248a4/