Kibana Dashboards and Lens Visualizations
Create, update, and delete Kibana dashboards and standalone Lens visualizations using the Kibana 9.4+ Dashboards and
Visualizations APIs. Produce minimal, diffable JSON bodies; prefer inline panel definitions over library references; and
choose the correct dataset type (data view vs ES|QL) before writing metrics or chart layers.
Environment Configuration
This skill executes Elasticsearch operations through the elastic CLI. If the
elastic CLI is not installed, tell the user what it is needed for. Do
not guess credentials, call the HTTP API directly, or attempt other workarounds.
This skill references operations in HTTP-shorthand form (e.g., GET /, GET /_cat/indices, GET /{index}/_mapping,
GET /{index}/_settings/index.mode, POST /_query). The Operations table at the end of this document
maps each shorthand to the equivalent elastic CLI command — always use the CLI rather than calling the HTTP API
directly.
Prerequisites
Version requirement: Kibana 9.4+ (Dashboards and Visualizations APIs).
ES|QL placement:
- Standalone library charts:
PUT kbn:/api/visualizations/{id} with data_source.type: "esql".
- ES|QL panels embedded in a dashboard: inline
vis panel config with data_source.type: "esql" via
PUT kbn:/api/dashboards/{id}.
- Do not use
data_source.type: "data_view_reference" or index-pattern aggregations when the user explicitly requests
ES|QL — the persisted Lens state must use a text-based ES|QL datasource (textBased / esql), not a data-view count
operation.
Process
Verify Kibana connectivity. Call GET kbn:/api/status. If the call fails, stop and surface the error — do not
guess endpoints or credentials. Read version.number to confirm the cluster meets the 9.4+ requirement.
Classify the task. Decide whether the user needs a dashboard (collection of panels, optional time range), a
standalone Lens visualization (library item referenced by id or used alone), or both. Determine whether a
deterministic saved-object id was supplied — when given, use upsert (PUT) with that id rather than POST (which
auto-generates ids).
Choose the dataset type before building metrics or layers.
| User intent |
Dataset |
Metric / axis pattern |
| Simple count or aggregation on a saved data view |
data_source.type: "data_view_reference" with ref_id |
metrics: [{ type: "primary", operation: "count" }] (or other aggregation operations) |
| Ad-hoc index pattern |
data_source.type: "data_view_spec" with index_pattern and time_field |
Same aggregation operation fields |
| ES|QL query (explicit or complex logic) |
data_source.type: "esql" with query |
metrics: [{ type: "primary", column: "<alias>" }] or layer axes { column: "<alias>" } — never operation: "count" on the metric |
Write the aggregation in the ES|QL query (STATS count = COUNT()), then reference the resulting column by name.
Build a dashboard body when creating or updating dashboards. The request body is flat — title, panels, and
optional time_range at the root. Do not wrap in { data: ... } on write. Required fields:
title — exact string the user requested.
panels — array; use [] when the user asks for an empty dashboard (do not omit the key or invent panels).
time_range — when the user specifies a default time filter, set { "from": "<expr>", "to": "<expr>" } (for
example { "from": "now-7d", "to": "now" }). Supplying time_range persists the dashboard time filter on open
(equivalent to enabling time restore in the UI).
Upsert with a deterministic id:
{
"title": "Sales Overview",
"panels": [],
"time_range": { "from": "now-7d", "to": "now" }
}
Call PUT kbn:/api/dashboards/eval-sales-overview with the body above when the user supplies that id.
Inline ES|QL metric panel example (inside panels):
{
"type": "vis",
"id": "total-requests",
"grid": { "x": 0, "y": 0, "w": 12, "h": 6 },
"config": {
"title": "Total Requests",
"type": "metric",
"data_source": {
"type": "esql",
"query": "FROM logs* | STATS count = COUNT()"
},
"metrics": [{ "type": "primary", "column": "count" }]
}
}
Prefer inline config properties over config.ref_id for portable dashboards. Read
Dashboard API Reference for panel types, grid layout, and copy workflows.
Build a standalone Lens visualization when the user asks for a library chart. Use the Visualizations API. Upsert
with PUT kbn:/api/visualizations/{id} when an id is supplied; otherwise POST kbn:/api/visualizations and report
the generated id from the response.
ES|QL metric (total count from logs):
{
"type": "metric",
"title": "Total Requests",
"data_source": {
"type": "esql",
"query": "FROM logs* | STATS count = COUNT()"
},
"metrics": [{ "type": "primary", "column": "count" }]
}
Call PUT kbn:/api/visualizations/eval-total-requests when that id is required. The API persists a Lens saved object
whose datasource state uses ES|QL (textBased / esql), not an index-pattern aggregation.
Read Lens API Reference and
Chart Types Reference for xy, gauge, heatmap, and other chart schemas.
Execute and confirm. Perform the write with PUT kbn:/api/dashboards/{id} or PUT kbn:/api/visualizations/{id}
(or POST when no id is supplied). Confirm with GET kbn:/api/dashboards/{id} or
GET kbn:/api/visualizations/{id}. Report the id and title back to the user — do not claim success without a
successful read-back.
List, export, or delete when requested. Call GET kbn:/api/dashboards or GET kbn:/api/visualizations to
discover existing objects. Call DELETE kbn:/api/dashboards/{id} or DELETE kbn:/api/visualizations/{id} to remove
objects. For bulk export or import of saved objects, call POST kbn:/api/saved_objects/_export or
POST kbn:/api/saved_objects/_import.
Dashboard grid
Dashboards use a 48-column grid. On 16:9 screens, roughly 20–24 rows fit above the fold — target 8–12 panels
in that band.
| Width |
Columns |
Height (rows) |
Use case |
| Full |
48 |
14–16 |
Wide time series, tables |
| Half |
24 |
10–12 |
Primary charts |
| Quarter |
12 |
5–6 |
KPI metrics |
| Sixth |
8 |
4–5 |
Dense metric rows |
Grid packing: When stacking rows, set the next panel's y to the previous panel's y + h. Panels sharing a row
should use the same h. Do not add markdown panels as dashboard titles — use descriptive chart titles instead.
ES|QL patterns
Time series bucket (dashboard time picker injects ?_tstart / ?_tend):
FROM logs*
| WHERE @timestamp <= ?_tend AND @timestamp > ?_tstart
| STATS count = COUNT() BY BUCKET(@timestamp, 75, ?_tstart, ?_tend)
Set "scale": "temporal" on the x-axis for time-series xy charts. See
Chart Types Reference for axis and layer details.
Static reference values — use EVAL in the query, then reference the column:
FROM logs* | STATS count = COUNT() | EVAL goal = 15000
Examples
Example JSON definitions live under assets/: demo-dashboard.json, dashboard-with-visualizations.json,
metric-esql.json, bar-chart-esql.json, line-chart-timeseries.json.
Guidelines
- Match the user's id and title exactly when supplied — do not substitute auto-generated ids.
- Honor empty panels — when the user asks for
panels: [], send an empty array; do not add placeholder panels.
- ES|QL when requested — use
data_source.type: "esql" and column references; never satisfy an ES|QL request with
operation: "count" on a data view.
- Minimal payloads — omit derivable defaults; let the API inject styling and metadata.
- Confirm writes — always read back with
GET after create or update.
- Read references before complex charts — metric and xy schemas differ between data view and ES|QL; consult
Chart Types Reference before generating partition or table charts.
Common issues
| Error |
Likely cause |
Fix |
| 404 on GET after PUT |
Wrong id or space |
Confirm id and retry GET kbn:/api/dashboards/{id} |
| 400 validation |
ES|QL column mismatch |
Align metrics[].column / layer column with STATS aliases in the query |
| ES|QL panel saved as data view |
Wrong dataset type |
Use data_source.type: "esql", not data_view_reference |
| Empty dashboard missing time filter |
Omitted time_range |
Include { "from": "now-7d", "to": "now" } when a default range is required |
| XY chart failure |
Missing layer data_source |
Put data_source inside each layer, not only at the root |
Operations
As of CLI v0.3.0 the Dashboards and Visualizations APIs have dedicated elastic kb dashboards and
elastic kb visualizations commands for listing, reading, updating, and deleting objects by id. The create-*-redirect
commands do not accept a request body yet, so to write a new object supply an id and use the update-*-redirect (PUT)
command, which carries the JSON body via --input-file. To author several objects at once, build a saved-object NDJSON
and import it with post-saved-objects-import (read it back with post-saved-objects-export).
| HTTP API (shorthand) |
elastic CLI command |
GET kbn:/api/status |
elastic kb system get-status |
POST kbn:/api/saved_objects/_import |
elastic kb saved-objects post-saved-objects-import --file '<path.ndjson>' --overwrite |
POST kbn:/api/saved_objects/_export |
elastic kb saved-objects post-saved-objects-export --objects '[{"type":"<type>","id":"<id>"}]' |
GET kbn:/api/dashboards |
elastic kb dashboards get-dashboards-redirect |
GET kbn:/api/dashboards/{id} |
elastic kb dashboards get-dashboard-redirect --id '<id>' |
PUT kbn:/api/dashboards/{id} |
elastic kb dashboards update-dashboard-redirect --id '<id>' --input-file '<path.json>' |
DELETE kbn:/api/dashboards/{id} |
elastic kb dashboards delete-dashboard-redirect --id '<id>' |
POST kbn:/api/dashboards (no id) |
create-dashboard-redirect takes no body yet — supply an id and use update-dashboard-redirect, or author via post-saved-objects-import (type dashboard) |
GET kbn:/api/visualizations |
elastic kb visualizations get-visualizations-redirect |
GET kbn:/api/visualizations/{id} |
elastic kb visualizations get-visualization-redirect --id '<id>' |
PUT kbn:/api/visualizations/{id} |
elastic kb visualizations update-visualization-redirect --id '<id>' --input-file '<path.json>' |
DELETE kbn:/api/visualizations/{id} |
elastic kb visualizations delete-visualization-redirect --id '<id>' |
POST kbn:/api/visualizations (no id) |
create-visualization-redirect takes no body yet — supply an id and use update-visualization-redirect, or author via post-saved-objects-import (type lens) |
1---2name: kibana-dashboards3description: Create and manage Kibana Dashboards and Lens visualizations. Use when you need to define dashboards and visualizations declaratively, version control them, or automate their deployment.4---5
6# Kibana Dashboards and Lens Visualizations
7
8Create, update, and delete Kibana dashboards and standalone Lens visualizations using the Kibana 9.4+ Dashboards and
9Visualizations APIs. Produce minimal, diffable JSON bodies; prefer inline panel definitions over library references; and
10choose the correct dataset type (data view vs ES|QL) before writing metrics or chart layers.
11
12<!-- begin-partial: preamble -->
13
14## Environment Configuration
15
16This skill executes Elasticsearch operations through the `elastic` CLI. If the
17[`elastic` CLI](https://github.com/elastic/cli#configuration) is not installed, tell the user what it is needed for. Do
18not guess credentials, call the HTTP API directly, or attempt other workarounds.
19
20This skill references operations in HTTP-shorthand form (e.g., `GET /`, `GET /_cat/indices`, `GET /{index}/_mapping`,
21`GET /{index}/_settings/index.mode`, `POST /_query`). The [Operations](#operations) table at the end of this document
22maps each shorthand to the equivalent `elastic` CLI command — always use the CLI rather than calling the HTTP API
23directly.
24
25<!-- end-partial: preamble -->
26
27## Prerequisites
28
29**Version requirement:** Kibana 9.4+ (Dashboards and Visualizations APIs).
30
31**ES|QL placement:**
32
33- Standalone library charts: `PUT kbn:/api/visualizations/{id}` with `data_source.type: "esql"`.
34- ES|QL panels embedded in a dashboard: inline `vis` panel `config` with `data_source.type: "esql"` via
35 `PUT kbn:/api/dashboards/{id}`.
36- Do not use `data_source.type: "data_view_reference"` or index-pattern aggregations when the user explicitly requests
37 ES|QL — the persisted Lens state must use a text-based ES|QL datasource (`textBased` / `esql`), not a data-view count
38 operation.
39
40## Process
41
421. **Verify Kibana connectivity.** Call `GET kbn:/api/status`. If the call fails, stop and surface the error — do not
43 guess endpoints or credentials. Read `version.number` to confirm the cluster meets the 9.4+ requirement.
44
452. **Classify the task.** Decide whether the user needs a **dashboard** (collection of panels, optional time range), a
46 **standalone Lens visualization** (library item referenced by id or used alone), or **both**. Determine whether a
47 deterministic saved-object id was supplied — when given, use upsert (`PUT`) with that id rather than `POST` (which
48 auto-generates ids).
49
503. **Choose the dataset type before building metrics or layers.**
51
52 | User intent | Dataset | Metric / axis pattern |
53 | ------------------------------------------------ | -------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
54 | Simple count or aggregation on a saved data view | `data_source.type: "data_view_reference"` with `ref_id` | `metrics: [{ type: "primary", operation: "count" }]` (or other aggregation operations) |
55 | Ad-hoc index pattern | `data_source.type: "data_view_spec"` with `index_pattern` and `time_field` | Same aggregation `operation` fields |
56 | ES\|QL query (explicit or complex logic) | `data_source.type: "esql"` with `query` | `metrics: [{ type: "primary", column: "<alias>" }]` or layer axes `{ column: "<alias>" }` — **never** `operation: "count"` on the metric |
57
58 Write the aggregation in the ES|QL query (`STATS count = COUNT()`), then reference the resulting column by name.
59
604. **Build a dashboard body when creating or updating dashboards.** The request body is flat — `title`, `panels`, and
61 optional `time_range` at the root. Do not wrap in `{ data: ... }` on write. Required fields:
62 - `title` — exact string the user requested.
63 - `panels` — array; use `[]` when the user asks for an empty dashboard (do not omit the key or invent panels).
64 - `time_range` — when the user specifies a default time filter, set `{ "from": "<expr>", "to": "<expr>" }` (for
65 example `{ "from": "now-7d", "to": "now" }`). Supplying `time_range` persists the dashboard time filter on open
66 (equivalent to enabling time restore in the UI).
67
68 **Upsert with a deterministic id:**
69
70 ```json
71 {
72 "title": "Sales Overview",
73 "panels": [],
74 "time_range": { "from": "now-7d", "to": "now" }
75 }
76 ```
77
78 Call `PUT kbn:/api/dashboards/eval-sales-overview` with the body above when the user supplies that id.
79
80 **Inline ES|QL metric panel example** (inside `panels`):
81
82 ```json
83 {
84 "type": "vis",
85 "id": "total-requests",
86 "grid": { "x": 0, "y": 0, "w": 12, "h": 6 },
87 "config": {
88 "title": "Total Requests",
89 "type": "metric",
90 "data_source": {
91 "type": "esql",
92 "query": "FROM logs* | STATS count = COUNT()"
93 },
94 "metrics": [{ "type": "primary", "column": "count" }]
95 }
96 }
97 ```
98
99 Prefer inline `config` properties over `config.ref_id` for portable dashboards. Read
100 [Dashboard API Reference](references/dashboard-api-reference.md) for panel types, grid layout, and copy workflows.
101
1025. **Build a standalone Lens visualization when the user asks for a library chart.** Use the Visualizations API. Upsert
103 with `PUT kbn:/api/visualizations/{id}` when an id is supplied; otherwise `POST kbn:/api/visualizations` and report
104 the generated id from the response.
105
106 **ES|QL metric (total count from logs):**
107
108 ```json
109 {
110 "type": "metric",
111 "title": "Total Requests",
112 "data_source": {
113 "type": "esql",
114 "query": "FROM logs* | STATS count = COUNT()"
115 },
116 "metrics": [{ "type": "primary", "column": "count" }]
117 }
118 ```
119
120 Call `PUT kbn:/api/visualizations/eval-total-requests` when that id is required. The API persists a Lens saved object
121 whose datasource state uses ES|QL (`textBased` / `esql`), not an index-pattern aggregation.
122
123 Read [Lens API Reference](references/lens-api-reference.md) and
124 [Chart Types Reference](references/chart-types-reference.md) for xy, gauge, heatmap, and other chart schemas.
125
1266. **Execute and confirm.** Perform the write with `PUT kbn:/api/dashboards/{id}` or `PUT kbn:/api/visualizations/{id}`
127 (or `POST` when no id is supplied). Confirm with `GET kbn:/api/dashboards/{id}` or
128 `GET kbn:/api/visualizations/{id}`. Report the id and title back to the user — do not claim success without a
129 successful read-back.
130
1317. **List, export, or delete when requested.** Call `GET kbn:/api/dashboards` or `GET kbn:/api/visualizations` to
132 discover existing objects. Call `DELETE kbn:/api/dashboards/{id}` or `DELETE kbn:/api/visualizations/{id}` to remove
133 objects. For bulk export or import of saved objects, call `POST kbn:/api/saved_objects/_export` or
134 `POST kbn:/api/saved_objects/_import`.
135
136## Dashboard grid
137
138Dashboards use a **48-column** grid. On 16:9 screens, roughly **20–24 rows** fit above the fold — target **8–12 panels**
139in that band.
140
141| Width | Columns | Height (rows) | Use case |
142| ------- | ------- | ------------- | ------------------------ |
143| Full | 48 | 14–16 | Wide time series, tables |
144| Half | 24 | 10–12 | Primary charts |
145| Quarter | 12 | 5–6 | KPI metrics |
146| Sixth | 8 | 4–5 | Dense metric rows |
147
148**Grid packing:** When stacking rows, set the next panel's `y` to the previous panel's `y + h`. Panels sharing a row
149should use the same `h`. Do not add markdown panels as dashboard titles — use descriptive chart titles instead.
150
151## ES|QL patterns
152
153**Time series bucket** (dashboard time picker injects `?_tstart` / `?_tend`):
154
155```esql
156FROM logs*
157| WHERE @timestamp <= ?_tend AND @timestamp > ?_tstart
158| STATS count = COUNT() BY BUCKET(@timestamp, 75, ?_tstart, ?_tend)
159```
160
161Set `"scale": "temporal"` on the x-axis for time-series xy charts. See
162[Chart Types Reference](references/chart-types-reference.md) for axis and layer details.
163
164**Static reference values** — use `EVAL` in the query, then reference the column:
165
166```esql
167FROM logs* | STATS count = COUNT() | EVAL goal = 15000
168```
169
170## Examples
171
172Example JSON definitions live under [assets/](assets/): `demo-dashboard.json`, `dashboard-with-visualizations.json`,
173`metric-esql.json`, `bar-chart-esql.json`, `line-chart-timeseries.json`.
174
175## Guidelines
176
1771. **Match the user's id and title exactly** when supplied — do not substitute auto-generated ids.
1782. **Honor empty panels** — when the user asks for `panels: []`, send an empty array; do not add placeholder panels.
1793. **ES|QL when requested** — use `data_source.type: "esql"` and column references; never satisfy an ES|QL request with
180 `operation: "count"` on a data view.
1814. **Minimal payloads** — omit derivable defaults; let the API inject styling and metadata.
1825. **Confirm writes** — always read back with `GET` after create or update.
1836. **Read references before complex charts** — metric and xy schemas differ between data view and ES|QL; consult
184 [Chart Types Reference](references/chart-types-reference.md) before generating partition or table charts.
185
186## Common issues
187
188| Error | Likely cause | Fix |
189| ----------------------------------- | --------------------------- | ---------------------------------------------------------------------------- |
190| 404 on GET after PUT | Wrong id or space | Confirm id and retry `GET kbn:/api/dashboards/{id}` |
191| 400 validation | ES\|QL column mismatch | Align `metrics[].column` / layer `column` with `STATS` aliases in the query |
192| ES\|QL panel saved as data view | Wrong dataset type | Use `data_source.type: "esql"`, not `data_view_reference` |
193| Empty dashboard missing time filter | Omitted `time_range` | Include `{ "from": "now-7d", "to": "now" }` when a default range is required |
194| XY chart failure | Missing layer `data_source` | Put `data_source` inside each layer, not only at the root |
195
196## Operations
197
198As of CLI v0.3.0 the Dashboards and Visualizations APIs have dedicated `elastic kb dashboards` and
199`elastic kb visualizations` commands for listing, reading, updating, and deleting objects by id. The `create-*-redirect`
200commands do not accept a request body yet, so to write a new object supply an id and use the `update-*-redirect` (PUT)
201command, which carries the JSON body via `--input-file`. To author several objects at once, build a saved-object NDJSON
202and import it with `post-saved-objects-import` (read it back with `post-saved-objects-export`).
203
204| HTTP API (shorthand) | `elastic` CLI command |
205| -------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
206| `GET kbn:/api/status` | `elastic kb system get-status` |
207| `POST kbn:/api/saved_objects/_import` | `elastic kb saved-objects post-saved-objects-import --file '<path.ndjson>' --overwrite` |
208| `POST kbn:/api/saved_objects/_export` | `elastic kb saved-objects post-saved-objects-export --objects '[{"type":"<type>","id":"<id>"}]'` |
209| `GET kbn:/api/dashboards` | `elastic kb dashboards get-dashboards-redirect` |
210| `GET kbn:/api/dashboards/{id}` | `elastic kb dashboards get-dashboard-redirect --id '<id>'` |
211| `PUT kbn:/api/dashboards/{id}` | `elastic kb dashboards update-dashboard-redirect --id '<id>' --input-file '<path.json>'` |
212| `DELETE kbn:/api/dashboards/{id}` | `elastic kb dashboards delete-dashboard-redirect --id '<id>'` |
213| `POST kbn:/api/dashboards` (no id) | `create-dashboard-redirect` takes no body yet — supply an id and use `update-dashboard-redirect`, or author via `post-saved-objects-import` (type `dashboard`) |
214| `GET kbn:/api/visualizations` | `elastic kb visualizations get-visualizations-redirect` |
215| `GET kbn:/api/visualizations/{id}` | `elastic kb visualizations get-visualization-redirect --id '<id>'` |
216| `PUT kbn:/api/visualizations/{id}` | `elastic kb visualizations update-visualization-redirect --id '<id>' --input-file '<path.json>'` |
217| `DELETE kbn:/api/visualizations/{id}` | `elastic kb visualizations delete-visualization-redirect --id '<id>'` |
218| `POST kbn:/api/visualizations` (no id) | `create-visualization-redirect` takes no body yet — supply an id and use `update-visualization-redirect`, or author via `post-saved-objects-import` (type `lens`) |