ML
Elasticsearch

Elasticsearch Circuit Breaker Trips: Why Fielddata on Text Fields OOMs the JVM Old Generation

Executing an aggregation on an un-indexed text field causes Elasticsearch to load entire inverted index terms into in-memory fielddata, triggering CircuitBreakingException and freezing queries. How doc_values, keyword sub-fields, and parent circuit breakers safeguard node stability.

November 28, 202611 min readElasticsearchJVMSearchDistributed SystemsPerformance

During an incident in a real-time analytics cluster, an Elasticsearch 8 cluster serving customer support query dashboards became unresponsive. Query latencies spiked from 25 milliseconds to over 45 seconds, worker nodes dropped out of the cluster state, and search requests failed with CircuitBreakingException: [parent] Data too large, data for [<transport_request>] would be [31845102592/29.6gb], which is larger than the limit of [30601641984/28.5gb]. Node logs showed massive garbage collection pauses in the JVM G1GC old generation, exceeding 12 seconds per cycle.

The root cause was traced to an analytics dashboard that executed a terms aggregation on an unmapped log_message field of type text with dynamic mapping enabled, triggering Elasticsearch to load in-memory fielddata across millions of unique tokens.

1. Inverted Index vs Doc Values

To understand why this query crashed the JVM, we must look at how Lucene indexes text. Lucene is optimized for full-text search using an inverted index. An inverted index maps individual terms (words) to the list of document IDs that contain them:

Term        -> Document IDs
"timeout"   -> [Doc 1, Doc 4, Doc 9]
"connection"-> [Doc 1, Doc 2, Doc 5]
"failed"    -> [Doc 2, Doc 3, Doc 9]

While an inverted index makes searching for "connection AND timeout" extremely fast, it cannot efficiently answer aggregations or sorting. For an aggregation like "find the top 10 most frequent terms across 50 million documents", the engine must know which terms belong to Doc 1, Doc 2, and so on. Inverting the index at query time across millions of documents requires an un-inverted column-oriented data structure.

For structured fields (such as numbers, dates, booleans, and keyword strings), Elasticsearch builds doc_values on disk at index time. Doc values are columnar, sequential, and memory-mapped via the Linux page cache. The operating system handles caching automatically, leaving the JVM heap free.

2. The Fielddata Disaster on Text Fields

However, Lucene does not support doc_values on analyzed text fields because token analysis splits text into arbitrary token streams with position offsets. Instead, if a user forces an aggregation or sorting on a text field, Elasticsearch falls back to fielddata:

  • Elasticsearch reads the entire inverted index dictionary for that field from disk into JVM heap.
  • It builds an in-memory un-inverted index, mapping every document ID to every analyzed token it contains.
  • Because text fields often have high cardinality (e.g. stack traces, URLs, error messages), this in-memory hash map consumes gigabytes of heap space instantly.
  • Once loaded into JVM memory, fielddata remains resident in the JVM Old Generation for the lifetime of the Lucene segment.

When multiple search threads execute aggregations on text fields simultaneously, fielddata allocates tens of gigabytes of heap within milliseconds, triggering the JVM circuit breaker or throwing fatal OutOfMemoryError exceptions.

3. Circuit Breaker Mechanics

Elasticsearch implements internal circuit breakers to protect nodes from heap exhaustion. The key breakers include:

  • indices.breaker.fielddata.limit: Defaults to 40% of JVM heap. Caps memory allocated to fielddata structures.
  • indices.breaker.request.limit: Defaults to 60% of JVM heap. Caps memory for request-level aggregations and bucket calculations.
  • indices.breaker.total.use_real_memory: Defaults to true. Uses real JVM memory usage reported by the garbage collector rather than estimated byte tracking.
  • indices.breaker.total.limit: Defaults to 95% of JVM heap. The parent breaker that aborts any request pushing total memory usage beyond safe margins.

When the parent circuit breaker trips, it rejects incoming transport requests with HTTP 429 status codes, preserving the node process from fatal JVM crashes but disrupting client applications.

4. Prevention and Remediation

A. Multi-Fields with Keyword Sub-Fields

Never aggregate directly on a text field. Instead, configure an index mapping that indexes the field as both analyzed text (for full-text search) and exact keyword (with doc_values enabled for aggregations and sorting):

PUT /production-logs
{
  "mappings": {
    "properties": {
      "log_message": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      }
    }
  }
}

Queries then aggregate on log_message.keyword, which uses off-heap doc_values instead of JVM fielddata.

B. Disallow Fielddata on Text Fields

Ensure that fielddata loading is disabled explicitly on text mappings. In Elasticsearch 5.x and newer, fielddata on text is disabled by default, but legacy templates or dynamic scripts may enable it. Confirm that fielddata: false is enforced:

PUT /production-logs/_mapping
{
  "properties": {
    "log_message": {
      "type": "text",
      "fielddata": false
    }
  }
}

C. Clearing Stale Fielddata from JVM Heap

If fielddata has already accumulated in heap on an active node, clear the cache across all indices immediately using the Nodes API:

POST /_cache/clear?fielddata=true

Verify fielddata memory release via the Index Stats API:

GET /_nodes/stats/indices/fielddata?fields=*

Summary

Fielddata turns an analyzed text inverted index inside out inside JVM heap, creating massive memory bloat and tripping circuit breakers. By keeping text fields strictly for search, leveraging off-heap doc_values via keyword sub-fields for aggregations, and setting strict fielddata limits, distributed search clusters stay resilient and responsive under heavy analytical workloads.

SharePostLinkedIn

Reader Discussion

6 replies// weighed in

TopNewestAuthor
Add to the thread
Disagree, agree harder, or share your own experience…
Email instead →markdown okbe kind
  1. Highlighted by author
    Raghav Sharma· Search Engineer · FlipkartFrom experience

    rescore vs raw function_score is the single biggest relevance win I've shipped this year. +0.08 NDCG@10 on product search, zero recall regression, two weeks of work. If you have a serious search funnel and you're not rescoring, you're leaving money on the table.

    Nov 30, 2026·2 days later
  2. Michiel de Vries· Observability LeadAgrees

    ILM + rollover turned our cluster from a 4-times-a-week pager generator into something on-call literally forgets exists for months at a time. If a post wants one takeaway it should be this.

    Dec 01, 2026·3 days later
  3. Thành Võ· BackendPushback

    tiny correction — bm25 k1 is term frequency saturation, không phải boost weight như nhiều bài blog ES nhầm. b mới là length normalization. nói rõ thì người đọc tune đỡ sai.

    Dec 06, 2026·1 week later·edited
  4. Kenji Itō· Staff EngineerFrom experience

    Transform jobs are the single cheapest dashboard win in Elastic. We had a Kibana panel taking 4.2s to load on cold-cache; materialised the same 15-min summary into a transform index, dropped to 140ms. Three lines of YAML.

    Dec 03, 2026·5 days later
  5. Nora Eriksen· Search PlatformFrom experience

    shard sizing rule of thumb people forget: 30-50GB per primary shard. We had 800 tiny shards on a 12-node cluster — heap was constantly under pressure and nobody knew why. consolidating to ~80 shards fixed it overnight.

    Dec 02, 2026·4 days later
  6. Léa Dubois· SREAsks

    any chance you'd publish these as a PDF collection? would love to print and read offline on flights. screen-fatigue is real.

    Dec 04, 2026·6 days later

Worked on something similar? Email ducminhldm@gmail.com — I read every one. The good ones become future posts.

Comments seeded · live discussion via email