Kibana: Lens

This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production.

Checked on 2026-11-09 against Kibana 9.5.x.

Lens is the editor that Kibana opens by default when you add a chart to a dashboard. It is where the Bookshelf "service health" panels (request rate, 5xx ratio, latency percentiles, error logs by route) are built in the Kibana lab. Choosing the right chart for a question is covered in Choosing Visualizations; this page explains the editor itself, what each chart asks Elasticsearch for, and the features that matter for monitoring: formulas for ratios, time shift for "versus last week", reference lines for SLO thresholds and annotations for deployments. The Grafana counterpart is Grafana Graphs and Charts. Panels that Lens does not cover are in Maps, Vega & Other Panels, and the older editors it replaces are in Legacy Editors, Canvas & Graph.

Source: Kibana: Lens visualizations. Lens is generally available on Serverless and on the Elastic Stack.

Two modes: point-and-click and query

Source: Kibana: Lens visualizations (introduction).

Point-and-click. You pick a data view (see Data Views & Discover), drag fields into the layer pane and choose aggregations. Dragging a field selects an aggregation for you (Date histogram for a time field, Intervals for a number, Top values for a keyword), and the Suggestions strip proposes alternative chart types for the same data. New visualizations start as a bar or line chart. This mode is the quickest way to answer a question on a known data view, and it is the one that exposes formulas, time shift and the other features below.

Query mode. You write an ES|QL or PromQL query and then map the result columns to chart dimensions. Choose it for queries across several indices, complex filtering and custom calculations. The ES|QL flavour has its own page, ES|QL Visualizations & Variable Controls; the PromQL command is documented at ES|QL: PROMQL and the query languages are compared in Querying with KQL, ES|QL & PromQL.

Lens visualizations can also be created and managed programmatically through the Visualizations API (Serverless GA; on the Stack it was preview in 9.4 and is generally available since 9.5), which is the route used in Dashboards as Code.

Chart types and the aggregations behind them

Source: Kibana: Lens visualization types and the per-chart pages under Kibana: Build bar charts.

Every chart is a front end for an Elasticsearch aggregation (see Aggregations and Metric Types and Aggregation): bucket aggregations group documents (a terms aggregation per route, a date_histogram per minute, numeric intervals, KQL filters), and metric aggregations compute a number per bucket (count, average, sum, min, max, median, percentile, unique count). A dimension in the layer pane is one of these two kinds, and the chart type decides how many of each it needs.

Chart (page) Buckets and metrics it asks for Bookshelf use What to watch

Bar and Line, Area (XY)

Horizontal axis: date_histogram, terms or intervals. Vertical axis: a metric or formula. Optional Break down by, several metrics and extra layers.

Requests per minute split by status class; p95 latency over time.

Stacked bars suit two to seven segments; area charts hide overlapping series.

Metric

One primary metric, optional secondary metric, optional breakdown into one tile per value, trend line, maximum value and progress bar, colour by value.

Current 5xx ratio against its 5 % threshold; request rate with last week as the secondary metric.

Only the primary metric is required; a breakdown multiplies the tiles.

Gauge

A metric plus minimum, maximum and goal values (static, computed or inferred from the data), tick marks and colour bands.

Error budget consumed.

Without sensible bounds a gauge says nothing; prefer the metric chart with colour thresholds for ratios.

Table

Rows from terms or other buckets (several fields allowed), metrics as columns.

Slowest routes with request count, error count and p95.

Sorting and pagination are limited (see the FAQ on the Lens page).

Heat map

Two bucket dimensions (horizontal and vertical) and one metric for the colour.

Latency by route and hour of day; request volume by weekday and hour.

Colour ranges decide what looks alarming; set absolute thresholds.

Pie, Treemap, Waffle, Mosaic (partition)

One or more Slice by buckets and a metric. Multiple metrics are possible (not for mosaic).

Share of errors by exception class.

Parts of a whole only; more than a handful of slices is unreadable.

Tag cloud

A terms bucket sized by a metric.

Frequent log message words.

Decorative; a sorted table is more exact.

Region map

A terms bucket of region codes joined to boundary shapes, and a metric.

Not meaningful for Bookshelf, which has no geography.

For points, routes and layers use the Maps app.

Lens does not list a state timeline equivalent; status over time is usually a heat map or a bar chart with a threshold line.

What can go wrong. A terms bucket returns only the top values (the default depends on the version: 9 values on Serverless and on the Stack since 9.4, and 5 for the first and 3 for further dimensions before that), so anything below is folded into Other or dropped; raise the number or aggregate by a lower-cardinality field. An Include empty rows setting controls whether a time series shows zero buckets (off by default for bar charts on the Stack since 9.5). Field names also matter: bucketing by a text field fails, so use its keyword sub-field or a keyword mapping (see Mapping and Field Types).

Breakdowns

A breakdown splits one chart into a series per value of a field. For XY charts the options are Top values (up to four fields), Date histogram, Intervals, Filters or Terms ranked by count, alphabetical order, rarity, significance or a custom metric, with an ascending or descending direction, include and exclude lists and an optional Other group. The Collapse by setting merges the values of a dimension into one number (sum, min, max or average) when a chart needs the dimension for sorting but not for display. For monitoring, break down by a low-cardinality attribute such as route template or status class; a breakdown by user ID or raw URL produces an unreadable legend and an expensive query (see Storage, Retention and Cost on cardinality).

Formulas

A formula combines aggregations and maths in one dimension. It is how Lens computes ratios, which a plain count cannot do. The documentation’s filter-ratio example is the shape of the Bookshelf 5xx ratio (the field name depends on how the lab maps the telemetry; use the one Discover shows):

count(kql='http.response.status_code >= 500') / count()

Set the Value format of the dimension to Percent, add a reference line at 0.05 for the lab’s 5 % threshold (see below) and the chart reads like the Grafana panel for the same alert. Two further documented patterns are a week-over-week comparison, which repeats an aggregation with shift='1w', and a percent of total, which divides a sum by overall_sum of the same sum:

percentile(system.network.in.bytes, percentile=99) /
percentile(system.network.in.bytes, percentile=99, shift='1w')

sum(products.base_price) / overall_sum(sum(products.base_price))

Reference: Kibana: Use formulas to perform math. For latency, percentile(<latency field>, percentile=95) follows the same form; Elasticsearch computes percentiles approximately, and a percentile of per-minute buckets cannot be averaged into a longer window (see Metric Types and Aggregation). The Formula reference icon in the editor lists every function and its arguments, including moving averages, counter rates and differences; it is the authority for the functions available in your version.

What can go wrong. A formula divides bucket by bucket, so an empty bucket gives no point rather than zero; the Lens FAQ on gaps and Include empty rows explains the options. The kql= argument filters inside the formula only: it is separate from the query bar, which filters the whole chart. Counter metrics sent as OpenTelemetry cumulative sums need a rate function, not a plain sum, otherwise the chart climbs forever (see Metric Types and Aggregation).

Time shift

Time shift compares the current value with the value one interval earlier. Open the dimension, expand Advanced and enter a Time shift such as 1h, 1d or 1w; the shifted series is drawn alongside the live one. It answers "is this traffic normal for a Monday morning?" without a second query, and it is the Kibana counterpart of Grafana’s query-option time shift. In query mode the equivalent is a single STATS with per-aggregation WHERE filters anchored to ?_tend, documented at Kibana: ES|QL time shift.

Reference lines

Reference lines mark a value on any chart that has axes. Open Add layer and choose Reference lines, then place the line at a Static value, at a value computed by a quick function (for example the average of the series) or by a Formula. Icon, colour, line style and fill above or below are configurable. For Bookshelf, draw the lab’s thresholds: 0.05 on the 5xx ratio panel and 0.5 seconds on the p95 latency panel, so the dashboard shows the alert limit next to the data (the SLO-linked alerts are in Observability Rules). A line that is typed in by hand drifts from the rule it mirrors, so keep both values in one documented place.

Annotations

Annotations call out events on a chart. In an Annotations layer you place them at a Static date (a point or a range) or with a Custom query: a KQL query against any data view plus the field that holds the target date, so every document that matches becomes an annotation. A deployment marker is the typical use: index deployment events (one document per release) in a small data stream and annotate the latency chart with them, which turns "latency doubled at 14:05" into "latency doubled right after release 1.4.2". Annotation groups can be saved to the Visualize library and shared by several charts, and a change to the group applies to all of them. Annotation layers are a preview feature on the Stack.

Colour mapping, filters and sampling

  • Colour mapping fixes a colour per term so that a status class keeps its colour whatever the filters or sort order: 5xx always red, 2xx always green. It works on tables, XY breakdowns, partition charts and tag clouds, with categorical or gradient modes and palettes such as Elastic, Severity and the legacy Kibana palettes. It is GA on Serverless and on the Stack since 9.1 (preview in 9.0); the Severity and line-optimised palettes are GA on the Stack since 9.4. The page also warns about colour contrast.

  • Filters come from the query bar (the whole chart), the Filters function (per layer), legend clicks and filter pills.

  • Sampling (layer settings, a slider) trades accuracy for speed on very large data sets; it is a preview feature on the Stack. Do not use it on a panel that feeds a decision about an alert threshold, since the numbers are estimates.

  • Open in Discover and Inspect show the documents and the Elasticsearch requests behind a chart; Inspect can open the request in Dev Tools Console, the quickest way to see which aggregation a chart sent.

Verifying in the lab

With the kibana profile of the hands-on lab running and the load generator on:

  1. Open Dashboards, create a dashboard and add a Lens panel on the lab’s data view; drag @timestamp to build a request-count line chart, and confirm it moves while the load generator runs.

  2. Add the 5xx formula above, set Value format to Percent, add a reference line at 0.05 and break the chart down by route.

  3. Use Inspect > Requests and check that the request contains a date_histogram and, for the formula, a filter aggregation.

  4. Stop the application, wait a few minutes and observe the gap in the series; this is the symptom the "no data" alert of the lab detects.

In the books

Shah (Kibana 8.x Quick Start Guide, chapter 4) teaches Lens as drag and drop of fields onto a workspace, explains the layer pane and quick functions, and then shows that metric and bucket aggregations are what the charts ask Elasticsearch for. Konda (Elasticsearch in Action, chapter 13) and Paro (Elasticsearch 7.0 Cookbook, chapter 7) describe those same metric, bucket and pipeline aggregations from the REST side, which is the vocabulary behind the table above. What has changed since: the books predate formulas with shift, reference lines and annotation layers, colour mapping, the query mode and the Visualizations API, and Paro’s Elasticsearch 7 request syntax needs adapting to current releases. For the REST syntax itself use Aggregations.

Where to go next

The panels around Lens are in Building Dashboards and Controls & Drilldowns; sharing and reporting in Sharing, Reporting & Saved Objects.