kibana-dashboards
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseKibana Dashboards and Visualizations
Kibana仪表板与可视化
Overview
概述
The Kibana dashboards and visualizations APIs provide a declarative, Git-friendly format for defining dashboards and
visualizations. Definitions are minimal, diffable, and suitable for version control and LLM-assisted generation.
Key Benefits:
- Minimal payloads (no implementation details or derivable properties)
- Easy to diff in Git
- Consistent patterns for GitOps workflows
- Designed for LLM one-shot generation
- Robust validation via OpenAPI spec
Version Requirement: Kibana 9.4+ (SNAPSHOT)
Kibana仪表板和可视化API提供了一种声明式、对Git友好的格式来定义仪表板和可视化。定义内容简洁、可对比差异,适用于版本控制和大语言模型(LLM)辅助生成。
核心优势:
- 轻量化负载(无实现细节或可推导属性)
- 在Git中易于对比差异
- 适配GitOps工作流的一致模式
- 专为LLM一次性生成设计
- 通过OpenAPI规范实现可靠验证
版本要求: Kibana 9.4+(SNAPSHOT版本)
Important Caveats
重要注意事项
Inline vs Saved Object References: When embedding Lens panels in dashboards, prefer inlinedefinitions overattributesreferences. Inline definitions are more reliable and self-contained.savedObjectId
内联定义 vs 已保存对象引用: 在仪表板中嵌入Lens面板时,优先使用内联定义,而非attributes引用。内联定义更可靠且具备自包含性。savedObjectId
Quick Start
快速开始
Environment Configuration
环境配置
Kibana connection is configured via environment variables. Run to verify the
connection. If the test fails, suggest these setup options to the user, then stop. Do not try to explore further until a
successful connection test.
node scripts/kibana-dashboards.js testKibana连接通过环境变量配置。运行验证连接。如果测试失败,向用户建议以下设置选项,然后停止操作。在连接测试成功前,请勿进行进一步操作。
node scripts/kibana-dashboards.js testOption 1: Elastic Cloud (recommended for production)
选项1:Elastic Cloud(生产环境推荐)
bash
export KIBANA_CLOUD_ID="deployment-name:base64encodedcloudid"
export KIBANA_API_KEY="base64encodedapikey"bash
export KIBANA_CLOUD_ID="deployment-name:base64encodedcloudid"
export KIBANA_API_KEY="base64encodedapikey"Option 2: Direct URL with API Key
选项2:带API密钥的直接URL
bash
export KIBANA_URL="https://your-kibana:5601"
export KIBANA_API_KEY="base64encodedapikey"bash
export KIBANA_URL="https://your-kibana:5601"
export KIBANA_API_KEY="base64encodedapikey"Option 3: Basic Authentication
选项3:基础认证
bash
export KIBANA_URL="https://your-kibana:5601"
export KIBANA_USERNAME="elastic"
export KIBANA_PASSWORD="changeme"bash
export KIBANA_URL="https://your-kibana:5601"
export KIBANA_USERNAME="elastic"
export KIBANA_PASSWORD="changeme"Option 4: Local Development with start-local
选项4:使用start-local进行本地开发
Use start-local to spin up Elasticsearch/Kibana locally, then source the
generated :
.envbash
curl -fsSL https://elastic.co/start-local | sh
source elastic-start-local/.env
export KIBANA_URL="$KB_LOCAL_URL"
export KIBANA_USERNAME="elastic"
export KIBANA_PASSWORD="$ES_LOCAL_PASSWORD"Then run to verify the connection.
node scripts/kibana-dashboards.js test使用start-local在本地启动Elasticsearch/Kibana,然后加载生成的文件:
.envbash
curl -fsSL https://elastic.co/start-local | sh
source elastic-start-local/.env
export KIBANA_URL="$KB_LOCAL_URL"
export KIBANA_USERNAME="elastic"
export KIBANA_PASSWORD="$ES_LOCAL_PASSWORD"然后运行验证连接。
node scripts/kibana-dashboards.js testOptional: Skip TLS verification (development only)
可选:跳过TLS验证(仅开发环境)
bash
export KIBANA_INSECURE="true"bash
export KIBANA_INSECURE="true"Basic Workflow
基础工作流
bash
undefinedbash
undefinedTest connection and API availability
测试连接和API可用性
node scripts/kibana-dashboards.js test
node scripts/kibana-dashboards.js test
Dashboard operations
仪表板操作
node scripts/kibana-dashboards.js dashboard get <id>
echo '<json>' | node scripts/kibana-dashboards.js dashboard create -
echo '<json>' | node scripts/kibana-dashboards.js dashboard update <id> -
node scripts/kibana-dashboards.js dashboard delete <id>
node scripts/kibana-dashboards.js dashboard get <id>
echo '<json>' | node scripts/kibana-dashboards.js dashboard create -
echo '<json>' | node scripts/kibana-dashboards.js dashboard update <id> -
node scripts/kibana-dashboards.js dashboard delete <id>
Lens visualization operations
Lens可视化操作
node scripts/kibana-dashboards.js lens list
node scripts/kibana-dashboards.js lens get <id>
echo '<json>' | node scripts/kibana-dashboards.js lens create -
echo '<json>' | node scripts/kibana-dashboards.js lens update <id> -
node scripts/kibana-dashboards.js lens delete <id>
undefinednode scripts/kibana-dashboards.js lens list
node scripts/kibana-dashboards.js lens get <id>
echo '<json>' | node scripts/kibana-dashboards.js lens create -
echo '<json>' | node scripts/kibana-dashboards.js lens update <id> -
node scripts/kibana-dashboards.js lens delete <id>
undefinedDashboards API
仪表板API
Dashboard Definition Structure
仪表板定义结构
The API expects a flat request body with and at the root level. The response wraps these in a
envelope alongside , , and .
titlepanelsdataidmetaspacesjson
{
"title": "My Dashboard",
"panels": [ ... ],
"time_range": {
"from": "now-24h",
"to": "now"
}
}Note: Dashboard IDs are auto-generated by the API. The script also accepts the legacy wrapped formatand unwraps it automatically.{ id?, data: { title, panels }, spaces? }
API要求请求体为扁平化结构,根层级包含和。响应会将这些内容包裹在信封中,同时返回、和。
titlepanelsdataidmetaspacesjson
{
"title": "我的仪表板",
"panels": [ ... ],
"time_range": {
"from": "now-24h",
"to": "now"
}
}注意: 仪表板ID由API自动生成。脚本也接受传统的嵌套格式,并会自动将其展开。{ id?, data: { title, panels }, spaces? }
Create Dashboard
创建仪表板
bash
echo '{
"title": "Sales Dashboard",
"panels": [],
"time_range": { "from": "now-7d", "to": "now" }
}' | node scripts/kibana-dashboards.js dashboard create -bash
echo '{
"title": "销售仪表板",
"panels": [],
"time_range": { "from": "now-7d", "to": "now" }
}' | node scripts/kibana-dashboards.js dashboard create -Update Dashboard
更新仪表板
bash
echo '{
"title": "Updated Dashboard Title",
"panels": [ ... ]
}' | node scripts/kibana-dashboards.js dashboard update my-dashboard-id -bash
echo '{
"title": "更新后的仪表板标题",
"panels": [ ... ]
}' | node scripts/kibana-dashboards.js dashboard update my-dashboard-id -Dashboard with Inline Lens Panels (Recommended)
包含内联Lens面板的仪表板(推荐)
Use inline for self-contained, portable dashboards:
attributesjson
{
"title": "My Dashboard",
"panels": [
{
"type": "lens",
"uid": "metric-panel",
"grid": { "x": 0, "y": 0, "w": 12, "h": 6 },
"config": {
"attributes": {
"title": "",
"type": "metric",
"dataset": { "type": "esql", "query": "FROM logs | STATS total = COUNT(*)" },
"metrics": [{ "type": "primary", "operation": "value", "column": "total", "label": "Total Count" }]
}
}
},
{
"type": "lens",
"uid": "chart-panel",
"grid": { "x": 12, "y": 0, "w": 36, "h": 8 },
"config": {
"attributes": {
"title": "Events Over Time",
"type": "xy",
"layers": [
{
"type": "area",
"dataset": {
"type": "esql",
"query": "FROM logs | STATS count = COUNT(*) BY bucket = BUCKET(@timestamp, 75, ?_tstart, ?_tend)"
},
"x": { "operation": "value", "column": "bucket" },
"y": [{ "operation": "value", "column": "count" }]
}
]
}
}
}
],
"time_range": { "from": "now-24h", "to": "now" }
}使用内联创建自包含、可移植的仪表板:
attributesjson
{
"title": "我的仪表板",
"panels": [
{
"type": "lens",
"uid": "metric-panel",
"grid": { "x": 0, "y": 0, "w": 12, "h": 6 },
"config": {
"attributes": {
"title": "",
"type": "metric",
"dataset": { "type": "esql", "query": "FROM logs | STATS total = COUNT(*)" },
"metrics": [{ "type": "primary", "operation": "value", "column": "total", "label": "总计数" }]
}
}
},
{
"type": "lens",
"uid": "chart-panel",
"grid": { "x": 12, "y": 0, "w": 36, "h": 8 },
"config": {
"attributes": {
"title": "事件趋势",
"type": "xy",
"layers": [
{
"type": "area",
"dataset": {
"type": "esql",
"query": "FROM logs | STATS count = COUNT(*) BY bucket = BUCKET(@timestamp, 75, ?_tstart, ?_tend)"
},
"x": { "operation": "value", "column": "bucket" },
"y": [{ "operation": "value", "column": "count" }]
}
]
}
}
}
],
"time_range": { "from": "now-24h", "to": "now" }
}Copy Dashboard Between Spaces/Clusters
在空间/集群间复制仪表板
bash
undefinedbash
undefined1. Get dashboard from source
1. 从源端获取仪表板
node scripts/kibana-dashboards.js dashboard get source-dashboard > dashboard.json
node scripts/kibana-dashboards.js dashboard get source-dashboard > dashboard.json
2. Edit dashboard.json to change id and/or spaces
2. 编辑dashboard.json以修改id和/或spaces
3. Create on destination
3. 在目标端创建
node scripts/kibana-dashboards.js dashboard create dashboard.json
undefinednode scripts/kibana-dashboards.js dashboard create dashboard.json
undefinedDashboard Grid System
仪表板网格系统
Dashboards use a 48-column, infinite-row grid. On 16:9 screens, approximately 20-24 rows are visible without
scrolling. Design for density—place primary KPIs and key trends above the fold.
| Width | Columns | Height | Rows | Use Case |
|---|---|---|---|---|
| Full | 48 | Large | 14-16 | Wide time series, tables |
| Half | 24 | Standard | 10-12 | Primary charts |
| Quarter | 12 | Compact | 5-6 | KPI metrics |
| Sixth | 8 | Minimal | 4-5 | Dense metric rows |
Target: 8-12 panels above the fold. Use descriptive panel titles on the charts themselves instead of adding markdown headers.
Grid Packing Rules:
- Eliminate Dead Space: Always calculate the bottom edge () of every panel. When starting a new row or placing a panel below another, its
y + hcoordinate must exactly match theyof the panel immediately above it.y + h - Align Row Heights: If multiple panels are placed side-by-side in a row (e.g., sharing the same coordinate), they should generally have the exact same height (
y). If they do not, you must fill the resulting empty vertical space before placing the next full-width panel.h
仪表板采用48列、无限行网格。在16:9屏幕上,无需滚动即可看到大约20-24行内容。设计时需注重密度——将关键KPI和核心趋势放在首屏可见区域。
| 宽度 | 列数 | 高度 | 行数 | 使用场景 |
|---|---|---|---|---|
| 全屏 | 48 | 大尺寸 | 14-16 | 宽幅时间序列、表格 |
| 半屏 | 24 | 标准尺寸 | 10-12 | 主要图表 |
| 四分之一屏 | 12 | 紧凑尺寸 | 5-6 | KPI指标 |
| 六分之一屏 | 8 | 极小尺寸 | 4-5 | 高密度指标行 |
目标: 首屏显示8-12个面板。在图表本身使用描述性标题,而非添加Markdown标题。
网格排布规则:
- 消除空白区域: 始终计算每个面板的底部边缘坐标()。当开始新行或在某个面板下方放置新面板时,新面板的
y + h坐标必须与上方面板的y完全匹配。y + h - 对齐行高: 如果多个面板在同一行并排放置(例如,共享相同的坐标),它们通常应具有完全相同的高度(
y)。如果高度不同,在放置下一个全屏面板前,必须填充由此产生的垂直空白区域。h
Panel Schema
面板 Schema
json
{
"type": "lens",
"uid": "unique-panel-id",
"grid": { "x": 0, "y": 0, "w": 24, "h": 15 },
"config": { ... }
}| Property | Type | Required | Description |
|---|---|---|---|
| string | Yes | Embeddable type (e.g., |
| string | No | Unique panel ID (auto-generated if omitted) |
| object | Yes | Position and size ( |
| object | Yes | Panel-specific configuration |
json
{
"type": "lens",
"uid": "unique-panel-id",
"grid": { "x": 0, "y": 0, "w": 24, "h": 15 },
"config": { ... }
}| 属性 | 类型 | 是否必填 | 描述 |
|---|---|---|---|
| string | 是 | 可嵌入类型(例如: |
| string | 否 | 唯一面板ID(若省略则自动生成) |
| object | 是 | 位置和尺寸( |
| object | 是 | 面板专属配置 |
Lens Visualizations API
Lens可视化API
Supported Chart Types
支持的图表类型
| Type | Description | ES|QL Support |
|---|---|---|
| Single metric value display | Yes |
| Line, area, bar charts | Yes |
| Gauge visualizations | Yes |
| Heatmap charts | Yes |
| Tag/word cloud | Yes |
| Data tables | Yes |
| Region/choropleth maps | Yes |
| Partition charts | Yes |
| 类型 | 描述 | ES|QL支持 |
|---|---|---|
| 单指标值展示 | 是 |
| 折线图、面积图、柱状图 | 是 |
| 仪表盘可视化 | 是 |
| 热力图 | 是 |
| 标签/词云 | 是 |
| 数据表 | 是 |
| 区域/分级统计图 | 是 |
| 分区图 | 是 |
Dataset Types
数据集类型
There are three dataset types supported in the Lens API. Each uses different patterns for specifying metrics and
dimensions.
Lens API支持三种数据集类型,每种类型指定指标和维度的方式不同。
Data View Dataset
数据视图数据集
Use with aggregation operations. Kibana performs the aggregations automatically.
dataViewjson
{
"dataset": {
"type": "dataView",
"id": "90943e30-9a47-11e8-b64d-95841ca0b247"
}
}Available Aggregation Operations (for dataView):
| Operation | Description | Requires Field |
|---|---|---|
| Document count | No |
| Average value | Yes |
| Sum of values | Yes |
| Maximum value | Yes |
| Minimum value | Yes |
| Cardinality | Yes |
| Median value | Yes |
| Standard deviation | Yes |
| Percentile (with | Yes |
| Percentile rank (with | Yes |
| Last value (with | Yes |
| Time buckets (for x-axis) | Yes |
| Top values (for x-axis/breakdown) | Yes |
将与聚合操作配合使用。Kibana会自动执行聚合。
dataViewjson
{
"dataset": {
"type": "dataView",
"id": "90943e30-9a47-11e8-b64d-95841ca0b247"
}
}可用聚合操作(dataView):
| 操作 | 描述 | 是否需要字段 |
|---|---|---|
| 文档计数 | 否 |
| 平均值 | 是 |
| 值的总和 | 是 |
| 最大值 | 是 |
| 最小值 | 是 |
| 基数 | 是 |
| 中位数 | 是 |
| 标准差 | 是 |
| 百分位数(需 | 是 |
| 百分位排名(需 | 是 |
| 最后一个值(需 | 是 |
| 时间桶(用于X轴) | 是 |
| 高频值(用于X轴/分类) | 是 |
ES|QL Dataset
ES|QL数据集
Use with a query string. Reference the output columns using .
esql{ operation: 'value', column: 'column_name' }json
{
"dataset": {
"type": "esql",
"query": "FROM logs | STATS count = COUNT(), avg_bytes = AVG(bytes) BY host"
}
}ES|QL Column Reference Pattern:
json
{
"operation": "value",
"column": "count"
}Key Difference: With ES|QL, you write the aggregation in the query itself, then reference the resulting columns. With dataView, you specify the aggregation operation and Kibana performs it.
将与查询字符串配合使用。使用引用输出列。
esql{ operation: 'value', column: 'column_name' }json
{
"dataset": {
"type": "esql",
"query": "FROM logs | STATS count = COUNT(), avg_bytes = AVG(bytes) BY host"
}
}ES|QL列引用模式:
json
{
"operation": "value",
"column": "count"
}核心差异: 使用ES|QL时,聚合逻辑写在查询语句中,然后引用生成的列。使用dataView时,只需指定聚合操作,Kibana会自动执行。
Index Dataset
索引数据集
Use for ad-hoc index patterns without a saved data view:
indexjson
{
"dataset": {
"type": "index",
"index": "logs-*",
"time_field": "@timestamp"
}
}对于没有已保存数据视图的临时索引模式,使用:
indexjson
{
"dataset": {
"type": "index",
"index": "logs-*",
"time_field": "@timestamp"
}
}Examples
示例
For detailed schemas and all chart type options, see Chart Types Reference.
Metric (dataView):
json
{
"type": "metric",
"dataset": { "type": "dataView", "id": "90943e30-9a47-11e8-b64d-95841ca0b247" },
"metrics": [{ "type": "primary", "operation": "count", "label": "Total Requests" }]
}Metric (ES|QL):
json
{
"type": "metric",
"dataset": { "type": "esql", "query": "FROM logs | STATS count = COUNT()" },
"metrics": [{ "type": "primary", "operation": "value", "column": "count", "label": "Total Requests" }]
}XY Bar Chart (dataView):
json
{
"title": "Top Hosts",
"type": "xy",
"axis": { "x": { "title": { "visible": false } }, "left": { "title": { "visible": false } } },
"layers": [
{
"type": "bar_horizontal",
"dataset": { "type": "dataView", "id": "90943e30-9a47-11e8-b64d-95841ca0b247" },
"x": { "operation": "terms", "fields": ["host.keyword"], "size": 10 },
"y": [{ "operation": "count" }]
}
]
}XY Time Series (ES|QL):
json
{
"title": "Requests Over Time",
"type": "xy",
"axis": { "x": { "title": { "visible": false } }, "left": { "title": { "visible": false } } },
"layers": [
{
"type": "line",
"dataset": {
"type": "esql",
"query": "FROM logs | STATS count = COUNT() BY bucket = BUCKET(@timestamp, 75, ?_tstart, ?_tend)"
},
"x": { "operation": "value", "column": "bucket" },
"y": [{ "operation": "value", "column": "count" }]
}
]
}Tip: Always hide axis titles when the panel title is descriptive. Usefor categorical data with long labels.bar_horizontal
如需详细Schema和所有图表类型选项,请查看图表类型参考。
指标图(dataView):
json
{
"type": "metric",
"dataset": { "type": "dataView", "id": "90943e30-9a47-11e8-b64d-95841ca0b247" },
"metrics": [{ "type": "primary", "operation": "count", "label": "总请求数" }]
}指标图(ES|QL):
json
{
"type": "metric",
"dataset": { "type": "esql", "query": "FROM logs | STATS count = COUNT()" },
"metrics": [{ "type": "primary", "operation": "value", "column": "count", "label": "总请求数" }]
}XY柱状图(dataView):
json
{
"title": "热门主机",
"type": "xy",
"axis": { "x": { "title": { "visible": false } }, "left": { "title": { "visible": false } } },
"layers": [
{
"type": "bar_horizontal",
"dataset": { "type": "dataView", "id": "90943e30-9a47-11e8-b64d-95841ca0b247" },
"x": { "operation": "terms", "fields": ["host.keyword"], "size": 10 },
"y": [{ "operation": "count" }]
}
]
}XY时间序列图(ES|QL):
json
{
"title": "请求趋势",
"type": "xy",
"axis": { "x": { "title": { "visible": false } }, "left": { "title": { "visible": false } } },
"layers": [
{
"type": "line",
"dataset": {
"type": "esql",
"query": "FROM logs | STATS count = COUNT() BY bucket = BUCKET(@timestamp, 75, ?_tstart, ?_tend)"
},
"x": { "operation": "value", "column": "bucket" },
"y": [{ "operation": "value", "column": "count" }]
}
]
}提示: 当面板标题具备描述性时,始终隐藏轴标题。对于标签较长的分类数据,使用(水平柱状图)。bar_horizontal
Full Documentation
完整文档
- Dashboard API Reference — Dashboard endpoints and schemas
- Lens API Reference — Lens visualization endpoints
- Chart Types Reference — Detailed schemas for each chart type
- Example Definitions — Ready-to-use definitions
- 仪表板API参考 — 仪表板端点和Schema
- Lens API参考 — Lens可视化端点
- 图表类型参考 — 各图表类型的详细Schema
- 示例定义 — 可直接使用的定义文件
Key Example Files
关键示例文件
- — Complete dashboard with inline Lens panels (dataView format)
assets/demo-dashboard.json - — Dashboard with ES|QL format (for future reference)
assets/dashboard-with-lens.json - — Standalone metric visualization
assets/metric-esql.json - — Bar chart example
assets/bar-chart-esql.json - — Time series line chart
assets/line-chart-timeseries.json
- — 包含内联Lens面板的完整仪表板(dataView格式)
assets/demo-dashboard.json - — ES|QL格式的仪表板(供未来参考)
assets/dashboard-with-lens.json - — 独立指标可视化
assets/metric-esql.json - — 柱状图示例
assets/bar-chart-esql.json - — 时间序列折线图
assets/line-chart-timeseries.json
Common Issues
常见问题
| Error | Solution |
|---|---|
| "401 Unauthorized" | Check KIBANA_USERNAME/PASSWORD or KIBANA_API_KEY |
| "404 Not Found" | Verify dashboard/visualization ID exists |
| "409 Conflict" | Dashboard/viz with that ID already exists; delete first or use update |
| "id not allowed in PUT" | Remove |
| Schema validation error | For ES|QL: ensure column names match query output; use |
ES|QL missing | ES|QL requires |
Metric uses | Metric chart requires |
Tagcloud uses | Tagcloud requires |
Datatable uses | ES|QL datatable requires |
| XY chart fails | Put |
| Heatmap property names | Use |
| savedObjectId panels missing | Prefer inline |
| 错误信息 | 解决方案 |
|---|---|
| "401 Unauthorized" | 检查KIBANA_USERNAME/PASSWORD或KIBANA_API_KEY |
| "404 Not Found" | 验证仪表板/可视化ID是否存在 |
| "409 Conflict" | 该ID的仪表板/可视化已存在;先删除或使用update操作 |
| "id not allowed in PUT" | 从更新请求体中移除 |
| Schema验证错误 | 对于ES|QL:确保列名与查询输出匹配;使用 |
ES|QL缺少 | ES|QL要求使用 |
指标图使用 | 指标图需要 |
标签云使用 | 标签云需要 |
数据表使用 | ES|QL数据表需要 |
| XY图表加载失败 | 将 |
| 热力图属性名称 | 使用 |
| savedObjectId面板缺失 | 优先使用内联 |
Guidelines
指南
- Design for density — Operational dashboards must show 8-12 panels above the fold (within the first 24 rows). Use
compact panel heights: metrics MUST be to
h=4, and charts MUST beh=6toh=8.h=12 - Never use Markdown for titles/headers — Do NOT add panels to act as dashboard titles or section dividers. This wastes critical vertical space. Use descriptive panel titles on the charts themselves.
DASHBOARD_MARKDOWN - Prioritize above the fold — Primary KPIs and key trends must be placed at . Deep-dives and data tables should be placed below the charts.
y=0 - Use descriptive chart titles — Write titles that explain what the chart shows (e.g., "Revenue by Product
Category"). Hide axis labels with to reduce clutter
axis.x.title.visible: false - Choose the right dataset type — Use for simple aggregations,
dataViewfor complex queries with joins, transformations, or custom logicesql - Inline Lens definitions — Prefer over
config.attributesfor portable dashboardsconfig.savedObjectId - Test connection first — Run before creating resources
node scripts/kibana-dashboards.js test - Get existing examples — Use to see the exact schema for different chart types
lens get <id> - Avoid redundant metric labels — For ES|QL metrics, avoid using both a panel title and an inner metric label, as
it wastes space. Set the panel to
titleand configure the human-readable label by aliasing the ES|QL column name using backticks (e.g.,""andSTATS `Total Requests` = COUNT())."column": "Total Requests"
- 注重密度设计 — 运维仪表板必须在首屏(前24行)显示8-12个面板。使用紧凑的面板高度:指标图高度必须为至
h=4,图表高度必须为h=6至h=8。h=12 - 切勿使用Markdown作为标题/页眉 — 不要添加面板作为仪表板标题或分区分隔符,这会浪费宝贵的垂直空间。在图表本身使用描述性标题。
DASHBOARD_MARKDOWN - 首屏优先展示关键内容 — 核心KPI和关键趋势必须放在位置。深度分析内容和数据表应放在图表下方。
y=0 - 使用描述性图表标题 — 标题需清晰说明图表展示的内容(例如:"按产品分类的收入")。通过设置隐藏轴标签以减少视觉干扰
axis.x.title.visible: false - 选择合适的数据集类型 — 简单聚合使用,包含连接、转换或自定义逻辑的复杂查询使用
dataViewesql - 内联Lens定义 — 为实现可移植性,优先使用而非
config.attributesconfig.savedObjectId - 先测试连接 — 创建资源前运行
node scripts/kibana-dashboards.js test - 获取现有示例 — 使用查看不同图表类型的准确Schema
lens get <id> - 避免重复的指标标签 — 对于ES|QL指标,避免同时使用面板标题和内部指标标签,这会浪费空间。将面板设置为
title,并通过ES|QL列别名(例如:""和STATS `总请求数` = COUNT())配置易读的标签。"column": "总请求数"
Schema Differences: dataView vs ES|QL
Schema差异:dataView vs ES|QL
| Aspect | dataView | ES|QL |
|---|---|---|
| Dataset | | |
| Metric chart | | |
| XY columns | | |
| Static values | | Use |
| XY dataset | Inside each layer | Inside each layer |
| Tagcloud | | |
| Datatable props | | |
Key Pattern: ES|QL always usesto reference columns from the query result. The aggregation happens in the ES|QL query itself.{ operation: 'value', column: 'column_name' }
| 方面 | dataView | ES|QL |
|---|---|---|
| 数据集 | | |
| 指标图 | | |
| XY列 | | |
| 静态值 | | 在查询中使用 |
| XY数据集 | 放在每个layer内部 | 放在每个layer内部 |
| 标签云 | | |
| 数据表属性 | | |
核心模式: ES|QL始终使用引用查询结果中的列。聚合逻辑在ES|QL查询语句中完成。{ operation: 'value', column: 'column_name' }
ES|QL: Time Bucketing
ES|QL:时间分桶
For time series charts, use the function to create "auto" buckets that automatically scale with the time range.
Always use instead of hardcoded intervals like
:
BUCKETBUCKET(@timestamp, 75, ?_tstart, ?_tend)DATE_TRUNC(1 hour, @timestamp)esql
FROM logs | STATS count = COUNT() BY bucket = BUCKET(@timestamp, 75, ?_tstart, ?_tend)对于时间序列图表,使用函数创建"自动"分桶,分桶会随时间范围自动调整。始终使用,而非硬编码间隔(如):
BUCKETBUCKET(@timestamp, 75, ?_tstart, ?_tend)DATE_TRUNC(1 hour, @timestamp)esql
FROM logs | STATS count = COUNT() BY bucket = BUCKET(@timestamp, 75, ?_tstart, ?_tend)ES|QL: Creating Static/Constant Values
ES|QL:创建静态/常量值
ES|QL does not support operations. Instead, create constant columns using :
static_valueEVALesql
FROM logs | STATS count = COUNT() | EVAL max_value = 20000, goal = 15000Then reference with . For dynamic reference values, use aggregation
functions like or in the query.
{ "operation": "value", "column": "max_value" }PERCENTILE()MAX()ES|QL不支持操作。可使用创建常量列:
static_valueEVALesql
FROM logs | STATS count = COUNT() | EVAL max_value = 20000, goal = 15000然后使用引用。对于动态参考值,在查询中使用或等聚合函数。
{ "operation": "value", "column": "max_value" }PERCENTILE()MAX()Design Principles
设计原则
The APIs follow these principles:
- Minimal definitions — Only required properties; defaults are injected
- No implementation details — No internal state or machine IDs
- Flat structure — Shallow nesting for easy diffing
- Semantic names — Clear, readable property names
- Git-friendly — Easy to track changes in version control
- LLM-optimized — Compact format suitable for one-shot generation
这些API遵循以下原则:
- 极简定义 — 仅包含必填属性;默认值会自动注入
- 无实现细节 — 无内部状态或机器ID
- 扁平化结构 — 浅层级嵌套便于对比差异
- 语义化命名 — 清晰、易读的属性名称
- Git友好 — 便于在版本控制中追踪变更
- LLM优化 — 紧凑格式适配一次性生成