Back to Technical Guides
Kibana & Elasticsearch Reading time: 7 min

Runtime Fields in Kibana: Calculating Metrics Without Reindexing

What happens when you realize a critical microservice logs its response latency or tenant ID inside an unparsed raw text string, right when you need a 30-day executive audit dashboard? With Kibana & Elasticsearch Runtime Fields ("Schema on Read"), you can extract, cast, and aggregate that metric immediately—without reindexing terabytes of historical data.

1. Schema on Write vs Schema on Read in Elasticsearch

Traditionally, Elasticsearch relies on Schema on Write: documents are parsed and indexed according to a strict mapping at ingestion time. While this delivers blazing-fast queries, it becomes a bottleneck if a field was mapped with the wrong type (e.g., keyword instead of double) or omitted from your Logstash/Ingest pipeline.

Runtime Fields bring Schema on Read: the field takes zero disk space in the inverted index and is evaluated dynamically at query execution time.

2. Practical Example: Computing SLA Compliance with Painless

Directly from your Kibana Data View (or index mapping), you can define a Runtime Field backed by a Painless script or a dissect / grok pattern.

Here is how to create a dynamic sla_compliance field of type keyword based on event duration:

if (doc['event.duration'].size() == 0) {
    emit('Unknown');
    return;
}
double durationMs = doc['event.duration'].value / 1000000.0;
if (durationMs < 200) {
    emit('Compliant (< 200ms)');
} else if (durationMs < 1000) {
    emit('Degraded (200ms - 1s)');
} else {
    emit('Breached (> 1s)');
}

Once saved, sla_compliance appears in Discover and Lens just like any indexed field. You can filter on it via KQL and group by its values in charts immediately.

3. Best Practices to Protect Cluster Performance

Master These Techniques in Our 2-Day Hands-On Course

This topic is practiced extensively in our Data Analysis with Kibana (2-Day Course). Leave with production-ready templates and query optimization workflows tailored to your stack (On-site corporate or Live Virtual Classroom).

More Technical Guides

Kibana & Elasticsearch

ES|QL vs KQL vs Lucene: Which Query Language Should You Choose for Kibana?

Comprehensive architectural comparison between Lucene, KQL, and Elasticsearch's piped vector engine ES|QL: advantages, drawbacks, structural limits, and production recommendations.

Read Guide
Grafana & Time Series

5 Common PromQL Mistakes Slowing Down Your Grafana Dashboards

High cardinality explosions, unanchored regex matchers, misconfigured rate() windows, and heavy subqueries: how to audit and tune PromQL queries before they crash Prometheus.

Read Guide
Grafana & Time Series

Data Transformations in Grafana: The Guide to On-the-Fly Calculations

Join Prometheus time series with PostgreSQL metadata, compute SLA ratios across queries, or reshape data frames: master Grafana's internal transformation pipeline.

Read Guide