Kibana: ES|QL Visualizations & Variable Controls

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. Tested with Elasticsearch 9.5.6 and Kibana 9.5.6 in the hands-on lab (trial licence): the non-variable ES|QL queries of this page ran against the lab data; variable controls need the Kibana UI and were not exercised.

To do this by hand, follow ES|QL Panels and Variable Controls.

Most Kibana charts start from a data view and a point-and-click aggregation (see Lens). An ES|QL visualization starts from a query instead: you write the question once, in the piped query language, and Kibana turns the result table into a Lens chart. It is the natural way to chart a ratio of two filtered counts, to join indices with LOOKUP JOIN, to query without creating a data view first and to promote a query you tuned in Discover to a dashboard panel. The language itself is taught in Querying with KQL, ES|QL & PromQL and in Query Languages and Scripting; this page is about the charts, and about the variable controls (?name and ??name) that let a dashboard user change the query without editing it. The Grafana counterparts of the controls are the dashboard variables of Grafana Variables.

flowchart LR Q["ES|QL query in Discover or a dashboard panel"] --> R["Result table: columns"] R --> M["Column mapping: grouping, time bucket, metric"] M --> C["Lens chart: bar, line, area, metric, table"] V["Variable controls: ?name, ??name"] -->|"substituted before the query runs"| Q T["Time picker: ?_tstart, ?_tend"] -->|"substituted before the query runs"| Q

Creating an ES|QL visualization

Source: Kibana: Lens visualizations using ES|QL queries (editing and adding from Discover, creating from a dashboard).

From Discover. In the ES|QL mode of Discover (see Data Views & Discover), a query shows a chart when it transforms its result with STATS or KEEP, or when the result contains a time field. The time field is @timestamp, or the field that the query compares with ?_tstart and ?_tend. The query decides the default chart type (a histogram for a time bucket plus a count, for instance). Use the edit control to change the chart type and its options and save the result to a new or existing dashboard.

From a dashboard. In edit mode choose Add, then the ES|QL option (labelled Create visualization (query) in current versions; the menu path differs between 9.x releases), write the query and run it. The Suggestions panel proposes alternative configurations, and you can bind variable controls to the panel before choosing Apply and close. A dashboard with no data view can still be created this way.

Alerts. From an ES|QL panel you can create an Elasticsearch threshold rule: right-clicking a data point creates a rule whose threshold matches the point, and More actions creates one without a preset threshold. Security rule types are not supported here. The rule types themselves are in Rules & Stack Rule Types.

How result columns become chart dimensions

Source: Kibana: Lens visualizations using ES|QL queries (column mapping, time series charts).

Each column of the result becomes a candidate dimension, and the chart type decides which combination it needs:

Column kind How to produce it Typical use

Grouping

A source column, a BY grouping or EVAL

Categories, series, non-time axes

Time bucket

BUCKET or DATE_TRUNC on a time field

Horizontal axis of a time series

Numeric metric

Aggregations such as COUNT, SUM, AVG

Vertical axis, sizes, colours, gauges

For a time series: filter with WHERE on the dashboard time range, split it with BUCKET, aggregate, then set a line, area or bar chart and put the bucket on the horizontal axis and the metric on the vertical axis. If the time field is not @timestamp, use the other field in both the WHERE and the BUCKET. The 5xx ratio of Bookshelf, the same signal as the Lens formula, is one query (field names depend on how the lab maps the telemetry; use those Discover shows):

FROM traces-*
| WHERE @timestamp >= ?_tstart AND @timestamp < ?_tend AND service.name == "bookshelf"
| STATS total = COUNT(*), errors = COUNT(*) WHERE http.response.status_code >= 500
    BY bucket = BUCKET(@timestamp, 50, ?_tstart, ?_tend)
| EVAL error_ratio = TO_DOUBLE(errors) / total
| KEEP bucket, error_ratio

Reference: ES|QL: BUCKET and Kibana: Lens visualizations using ES|QL queries. ?_tstart and ?_tend are substituted with the bounds of the dashboard time picker, and BUCKET with a target count of 50 picks an interval that fills the range. Choose a line chart, bucket on the horizontal axis and error_ratio on the vertical axis; set the value format to a percentage in the axis options and the chart is the ES|QL twin of the Lens 5xx panel.

What can go wrong. A query that returns no time column draws a table or a single value, not a trend; a WHERE that hard-codes NOW() - 1 hour ignores the time picker, so zooming on the dashboard changes nothing; a division of two integers truncates, hence TO_DOUBLE. Chart settings persist across query edits while the new columns stay compatible and reset when they stop being so (for example after changing the chart type or the column set), so re-check axis formats after a larger edit.

Breaking a chart down by several fields

Source: Kibana: Lens visualizations using ES|QL queries (break down a chart by multiple fields).

For bar, line and area charts the breakdown dimension can hold several fields (generally available on the Stack since 9.4). Every unique combination of values becomes a series, labelled with the values joined by a separator. When a query groups by several fields, the first goes to the horizontal axis and the rest into the breakdown; you can add fields and reorder them to change the label order. Group by service.name and the status class, not by the raw URL: each combination is a series and a legend entry, so high-cardinality fields make the chart unreadable (see Storage, Retention and Cost).

Comparing with the previous period

The page shows how to compare the last seven days with the seven days before in a single query: one STATS with a WHERE per aggregation, both windows anchored to ?_tend so that they follow the time picker, and a CASE that returns null instead of dividing by an empty previous window. Adapted to Bookshelf, to find the routes whose traffic changed most:

FROM traces-*
| WHERE @timestamp >= ?_tend - 14 days AND @timestamp < ?_tend
| STATS current = COUNT(*) WHERE @timestamp >= ?_tend - 7 days,
        previous = COUNT(*) WHERE @timestamp < ?_tend - 7 days
    BY url.path
| EVAL change_pct = CASE(previous == 0, null, (current - previous) * 100.0 / previous)
| SORT change_pct DESC
| LIMIT 10

Reference: Kibana: ES|QL time shift. The same idea in point-and-click mode is the Time shift option of Lens.

Drilldowns, dashboard filters, fast mode and other options

Source: Kibana: Lens visualizations using ES|QL queries (drilldowns, ignore dashboard filters, fast mode, cross-project search).

  • Drilldowns from an ES|QL panel are Dashboard, URL and, since 9.5, Discover drilldowns (generally available on the Stack since 9.4). A Discover drilldown carries over the dashboard filters and queries. Only indexed fields work; fields computed at query time do not. Drilldown design is in Controls & Drilldowns.

  • Ignore dashboard filters (Stack since 9.5): in the layer settings turn off Use global filters so that a layer ignores filter pills and the search bar; the time range still applies. Use it for a reference layer such as "all traffic" under a filtered layer.

  • Fast mode returns estimated results for a query with exactly one STATS command, marked by a bolt badge. It is a preview on Serverless and on the Stack since 9.5, so do not build anything that depends on it.

  • Cross-project search with SET project_routing is Serverless only.

  • Emoji in result columns (for example from CASE) show in any text-based chart, which gives a cheap status column in a table.

Variable controls

Variable controls bind dashboard controls to variables in ES|QL queries. They are not the same as the standard dashboard controls (options list, range slider and time slider), which filter on data view fields; variable controls work inside the query, so they can change a filter value, the field a query groups by, a function parameter or even the aggregation. They appear as options lists. In 9.0 and 9.1 they were named ES|QL controls. Two syntaxes exist:

  • ?name is a value: a filter value or a function parameter. Multiple selection works only with these.

  • ??name is an identifier: a field name or a function. This syntax is a preview on Serverless and on the Stack since 9.1.

Control type Options come from

Static values

A list you type, or pick from a dropdown

Values from a query

An ES|QL query, which allows dynamic lists and chained controls

Fields

Field names (??name)

Functions

Functions or their configuration (??name; preview since 9.1)

Creating a control. In the query editor type ? (or wait for the autocomplete) and choose Create control; or, from the dashboard, choose Add, Controls, Variable control. In the flyout set the type, the values or the query, the variable name with its prefix, a label and single or multiple selection. A control that lists values from a query should be limited to the dashboard time range by adding WHERE @timestamp <= ?_tend AND @timestamp > ?_tstart to its own query, otherwise it offers values that do not exist in the period being looked at. Four uses for Bookshelf:

// a "service" control, values from a query
FROM metrics-*
| WHERE @timestamp <= ?_tend AND @timestamp > ?_tstart
| STATS BY service.name

// panel queries that use controls
FROM logs-*
| WHERE service.name == ?service
| STATS errors = COUNT(*) BY BUCKET(@timestamp, ?interval)

FROM logs-*
| STATS errors = COUNT(*) BY ??group_by

FROM logs-*
| STATS metric = ??function

Reference: Kibana: Add variable controls to a visualization (syntax and example queries). The first listing is the control’s own query; ??group_by offers field names such as url.path or http.response.status_code, and the ?interval control is a static list of interval values for the bucket size.

Multiple values, chaining and importing (preview since 9.2 and 9.3). With Allow multiple selections, wrap the filter in MV_CONTAINS(field, ?values) to require all the selected values or in MV_INTERSECTS(field, ?values) to match any of them (preview since 9.3). A control can depend on another by using the parent’s variable in its own query (geo.dest == ?region in the documentation’s example); create the parent first so autocomplete works, and expect a child whose selection is no longer valid to be flagged. Chaining narrows the options without filtering the whole dashboard (preview since 9.3). Controls from a Discover query reach a dashboard either with a Discover session saved to the library (preview since 9.2; in 9.2 and 9.3 only the first tab imports, from 9.4 you choose the tab) or with Save visualization to dashboard in Discover (generally available from 9.3).

Managing controls. A control can be pinned to the top of the dashboard or left in the body, edited, resized (pinned controls have minimum width and expansion settings from 9.4) or deleted. The placement decides which panels it affects (see Controls & Drilldowns). A dashboard holds at most 1,000 top-level items and 100 pinned controls. Deleting a control that a panel references breaks that panel until you change its query.

What can go wrong. A panel that mentions a variable that no control provides fails with an error; a ?? variable cannot take multiple values; and a Vega panel that uses a control needs params defaults for places without dashboard controls (the Vega page notes variable controls there as Serverless preview and Planned on the Stack). Use ?? for field names and ? for values; a value control cannot stand in for a field name.

Verifying in the lab

  1. In Discover (ES|QL mode) paste the 5xx ratio query, run it with the load generator on and confirm that a line chart appears; save it to a new dashboard.

  2. Add the service control from the listing, then add WHERE service.name == ?service to the panel and check that changing the control reruns the query (Inspect shows the substituted value).

  3. Add a ??group_by control with the options url.path and http.response.status_code and confirm that the table regroups.

  4. Right-click a point of the ratio chart, create a threshold rule from it and compare the result with the lab’s 5xx alert of 0.05 over five minutes (see Rules & Stack Rule Types).

In the books

Shah (Kibana 8.x Quick Start Guide, chapter 9) introduces ES|QL building blocks and how a query runs in Discover; its queries should be checked against the current language reference, because the chapter predates the TS command, LOOKUP JOIN, the time-picker parameters and variable controls. None of the other provided books covers ES|QL visualizations or controls: they (Paro, Chhajed and Melachi) work with the older aggregation-based editors, covered in Legacy Editors, Canvas & Graph.