Skip to content

feat(elasticsearch): add ES SQL query mode with SQL builder - #2293

Merged
jsers merged 3 commits into
mainfrom
feat/elasticsearch-sql-builder
Sep 9, 2026
Merged

jsers merged 3 commits into
mainfrom
feat/elasticsearch-sql-builder

Conversation

@jsers

@jsers jsers commented Aug 27, 2026 •

Copy link
Copy Markdown
Collaborator
  • Gate DSL/SQL switching behind cluster is_sql_supported (plus only)
  • Support Builder/Code edit modes via shared SQLBuilderModal
  • Preserve sql syntax in dashboard migrator and query contract
  • Strip editor-only fields (editMode, builderConfig, stale sql/keys) on submit

Summary by CodeRabbit

  • New Features
    • Added Elasticsearch and OpenSearch SQL query support for dashboards, alerts, recording rules, and graph previews.
    • Added SQL Code and Builder modes, including query previews, validation, and confirmation when switching modes.
    • Added dashboard options for time-series and table results.
  • Bug Fixes
    • Preserved SQL query settings during dashboard migration and serialization.
    • Prevented editor-only configuration and incompatible query fields from being saved.
  • Documentation
    • Added interface translations and labels for SQL and query builder workflows.

- Gate DSL/SQL switching behind cluster is_sql_supported (plus only)
- Support Builder/Code edit modes via shared SQLBuilderModal
- Preserve sql syntax in dashboard migrator and query contract
- Strip editor-only fields (editMode, builderConfig, stale sql/keys) on submit
@coderabbitai

coderabbitai Bot commented Aug 27, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: d10d8b55-a6f5-41c7-9213-1c3acad48a6d

📥 Commits

Reviewing files that changed from the base of the PR and between de8296a and 7d96d8a.

📒 Files selected for processing (27)
  • src/pages/alertRules/Form/utils.test.ts
  • src/pages/alertRules/Form/utils.ts
  • src/pages/dashboard/Detail/utils/dashboardMigrator.test.ts
  • src/pages/dashboard/Detail/utils/dashboardMigrator.ts
  • src/pages/dashboard/Editor/QueryEditor/Elasticsearch/QueryPanel.tsx
  • src/pages/dashboard/Renderer/datasource/contract.test.ts
  • src/pages/dashboard/Renderer/datasource/registry.ts
  • src/plugins/doris/AlertRule/Query.tsx
  • src/plugins/doris/Dashboard/QueryBuilder.tsx
  • src/plugins/doris/RecordingRules/Queries/index.tsx
  • src/plugins/elasticsearch/AlertRule/GraphPreview.tsx
  • src/plugins/elasticsearch/AlertRule/Queries/Query.tsx
  • src/plugins/elasticsearch/AlertRule/Queries/index.tsx
  • src/plugins/elasticsearch/RecordingRules/Queries/index.tsx
  • src/plugins/elasticsearch/components/SQLBuilderModal.tsx
  • src/plugins/elasticsearch/index.tsx
  • src/plugins/elasticsearch/locale/en_US.ts
  • src/plugins/elasticsearch/locale/es_ES.ts
  • src/plugins/elasticsearch/locale/fr_FR.ts
  • src/plugins/elasticsearch/locale/id_ID.ts
  • src/plugins/elasticsearch/locale/ja_JP.ts
  • src/plugins/elasticsearch/locale/ko_KR.ts
  • src/plugins/elasticsearch/locale/pt_BR.ts
  • src/plugins/elasticsearch/locale/ru_RU.ts
  • src/plugins/elasticsearch/locale/zh_CN.ts
  • src/plugins/elasticsearch/locale/zh_HK.ts
  • src/plugins/elasticsearch/services.ts

📝 Walkthrough

Walkthrough

Elasticsearch and OpenSearch queries now support SQL syntax in dashboards, alerts, graph previews, and recording rules. The changes add SQL editors, a SQL builder, capability checks, SQL-aware serialization, migration handling, validation, tests, and translations.

Changes

Elasticsearch SQL support

Layer / File(s) Summary
SQL query persistence and migration
src/pages/alertRules/Form/utils.ts, src/pages/alertRules/Form/utils.test.ts, src/pages/dashboard/Detail/utils/dashboardMigrator.ts, src/pages/dashboard/Detail/utils/dashboardMigrator.test.ts
Form processing removes editor-only state, clears syntax-incompatible fields, and preserves SQL metadata. Dashboard migration keeps SQL queries in SQL mode.
Dashboard SQL editor
src/pages/dashboard/Editor/QueryEditor/Elasticsearch/QueryPanel.tsx
The dashboard query panel detects cluster SQL support and provides SQL, DSL, Builder, and Code modes.
Alert SQL editor and builder
src/plugins/elasticsearch/AlertRule/Queries/*, src/plugins/elasticsearch/components/SQLBuilderModal.tsx, src/plugins/elasticsearch/locale/*
Alert queries support SQL editing, SQL building, SQL-specific keys, validation, previews, confirmation dialogs, and translated labels.
SQL request serialization and preview
src/pages/dashboard/Renderer/datasource/*, src/plugins/elasticsearch/AlertRule/GraphPreview.tsx, src/plugins/elasticsearch/services.ts
SQL targets use SQL-specific readiness checks and request payloads. Alert graph previews call esSQLDsQuery.
Recording-rule SQL integration
src/plugins/elasticsearch/RecordingRules/Queries/index.tsx, src/plugins/elasticsearch/index.tsx, src/plugins/doris/*
Recording rules render SQL fields when supported. The plugin exports the recording-rule query builder, and related mode-switch behavior is documented in comments.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant QueryEditor
  participant SQLBuilderModal
  participant ElasticsearchService
  participant DashboardRenderer
  User->>QueryEditor: Select SQL mode
  QueryEditor->>SQLBuilderModal: Open Builder
  SQLBuilderModal->>ElasticsearchService: Build SQL query
  ElasticsearchService-->>SQLBuilderModal: Return SQL and builder configuration
  SQLBuilderModal-->>QueryEditor: Update SQL, mode, and keys
  QueryEditor->>DashboardRenderer: Submit serialized SQL target
  DashboardRenderer->>ElasticsearchService: Execute SQL data request
  ElasticsearchService-->>DashboardRenderer: Return query data
Loading
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/elasticsearch-sql-builder

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

jsers added 2 commits August 27, 2026 16:14
…query type

- Extract inline valueKey validation into hasESValueKey helper in dashboard
  datasource registry, using native type narrowing for safer checks.
- Add optional ref field to esSQLDsQuery query type to match existing usage
  in GraphPreview and align with esLogsQuery.
editMode records the SQL Builder/Code view state and must be saved with
the rule config so it can be restored on re-edit. It is no longer omitted
from the query payload; query APIs do not consume it. builderConfig stays
stripped as Builder draft state, and ES DSL queries still clear leftover
sql/keys.
@jsers
jsers marked this pull request as ready for review September 9, 2026 02:43
Copilot AI lite review requested due to automatic review settings September 9, 2026 02:43
@jsers
jsers merged commit d343def into main Sep 9, 2026
1 of 2 checks passed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

There are confirmed issues that can break TypeScript builds and/or cause UI/query payload inconsistencies when SQL is not supported.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds an Elasticsearch SQL query mode (Plus-only) with a shared SQL Builder modal, and updates dashboard + alert-rule query contracts/migration so SQL mode can be persisted and executed consistently.

Changes:

  • Introduce a reusable SQLBuilderModal and integrate SQL (DSL/SQL + Builder/Code) switching into Dashboard and AlertRule Elasticsearch query editors.
  • Extend ES datasource query payloads/contracts (incl. ref support) and preserve syntax: 'sql' across dashboard migration/serialization.
  • Add/extend i18n strings and regression tests for the updated query contract + form submission behavior.
File summaries
File Description
src/plugins/elasticsearch/services.ts Extend ES query request typing (adds optional ref).
src/plugins/elasticsearch/RecordingRules/Queries/index.tsx Add ES SQL query config UI for recording rules (Plus-only, SQL-supported clusters).
src/plugins/elasticsearch/locale/zh_HK.ts Add SQL/builder/dashboard-mode translation keys.
src/plugins/elasticsearch/locale/zh_CN.ts Add SQL/builder/dashboard-mode translation keys.
src/plugins/elasticsearch/locale/ru_RU.ts Add SQL/builder/dashboard-mode translation keys.
src/plugins/elasticsearch/locale/pt_BR.ts Add SQL/builder/dashboard-mode translation keys.
src/plugins/elasticsearch/locale/ko_KR.ts Add SQL/builder/dashboard-mode translation keys.
src/plugins/elasticsearch/locale/ja_JP.ts Add SQL/builder/dashboard-mode translation keys.
src/plugins/elasticsearch/locale/id_ID.ts Add SQL/builder/dashboard-mode translation keys.
src/plugins/elasticsearch/locale/fr_FR.ts Add SQL/builder/dashboard-mode translation keys.
src/plugins/elasticsearch/locale/es_ES.ts Add SQL/builder/dashboard-mode translation keys.
src/plugins/elasticsearch/locale/en_US.ts Add SQL/builder/dashboard-mode translation keys.
src/plugins/elasticsearch/index.tsx Export ES recording-rule query builder entry point.
src/plugins/elasticsearch/components/SQLBuilderModal.tsx New shared SQL builder modal component (Plus query builder integration).
src/plugins/elasticsearch/AlertRule/Queries/Query.tsx Add DSL/SQL switching + Builder/Code UX for ES alert-rule queries.
src/plugins/elasticsearch/AlertRule/Queries/index.tsx Gate ES SQL support by cluster capability and pass into query UI.
src/plugins/elasticsearch/AlertRule/GraphPreview.tsx Add SQL preview execution path for ES alert rules.
src/plugins/doris/RecordingRules/Queries/index.tsx Comment clarification for builder switch behavior (no functional change).
src/plugins/doris/Dashboard/QueryBuilder.tsx Comment clarification for builder switch behavior (no functional change).
src/plugins/doris/AlertRule/Query.tsx Comment clarification for builder switch behavior (no functional change).
src/pages/dashboard/Renderer/datasource/registry.ts Update readiness + serialization for ES SQL and strip builder-only fields.
src/pages/dashboard/Renderer/datasource/contract.test.ts Add contract coverage for ES SQL timeSeries/raw request building.
src/pages/dashboard/Editor/QueryEditor/Elasticsearch/QueryPanel.tsx Add DSL/SQL switching + Builder/Code UX for ES dashboard queries.
src/pages/dashboard/Detail/utils/dashboardMigrator.ts Preserve syntax: 'sql' during v4 migration for ES/OpenSearch.
src/pages/dashboard/Detail/utils/dashboardMigrator.test.ts Add/adjust tests to ensure SQL syntax is preserved during migration.
src/pages/alertRules/Form/utils.ts Strip builderConfig/stale SQL fields on submit while preserving desired SQL state.
src/pages/alertRules/Form/utils.test.ts Add regression tests for new ES SQL submission behavior.
Review details
  • Files reviewed: 27/27 changed files
  • Comments generated: 5
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +130 to +134
const hasESValueKey = (keys: unknown) => {
if (!keys || typeof keys !== 'object' || Array.isArray(keys) || !('valueKey' in keys)) return false;
const valueKey = keys.valueKey;
return Array.isArray(valueKey) ? valueKey.length > 0 : typeof valueKey === 'string' && valueKey.trim().length > 0;
};
Comment on lines +84 to +90
useEffect(() => {
setSupportsSQL(false);
if (!IS_PLUS || !datasourceValue) return;
getESClusterInfo({ cate: esDatasourceCate, datasource_id: datasourceValue })
.then((info) => setSupportsSQL(info?.is_sql_supported ?? false))
.catch(() => setSupportsSQL(false));
}, [datasourceValue, esDatasourceCate]);
Comment on lines 49 to 60
const names = ['rule_config', 'queries'];
const queries = Form.useWatch(names);
const savedSyntax = Form.useWatch([...names, field.name, 'syntax']);
const syntax = supportsSQL && savedSyntax === 'sql' ? 'sql' : 'dsl';
const indexType = Form.useWatch([...names, field.name, 'index_type']);
const indexValue = Form.useWatch([...names, field.name, 'index']);
const indexPatternId = Form.useWatch([...names, field.name, 'index_pattern']);
const query = queries?.[field.name];
const editMode = query?.editMode ?? 'code';
const [builderModalVisible, setBuilderModalVisible] = useState(false);
const form = Form.useFormInstance();
const curIndexValue = useMemo(() => {
search_mode: esIndexMode !== 'all' ? esIndexMode : 'indices',
query: { range },
});
}, [visible, builderConfig, range, form]);
}
// Builder configuration is editor state used to reopen the builder. The
// datasource query APIs only need the generated query fields.
delete payload.builderConfig;
@flashduty

flashduty Bot commented Sep 9, 2026

Copy link
Copy Markdown

每日 i18n Review(2026-09-09)发现本 PR 新增的 QueryPanel.tsx 中 Builder/Code 分段标签与 label='Legend' 为硬编码文案(同文件已有 tES('builder.title')/tES('builder.code')/t('query.legend') 可复用),已在 #2320 修复。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants