Skip to content

[Lens powered by ES|QL] Enable topN support (Other disabled) for non-time-series charts - #290193

Merged
mariairiartef merged 3 commits into
elastic:mainfrom
mariairiartef:lens/2889-2
Sep 15, 2026
Merged

mariairiartef merged 3 commits into
elastic:mainfrom
mariairiartef:lens/2889-2

Conversation

@mariairiartef

@mariairiartef mariairiartef commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Part of kibana-team#2889

Users can Convert to ES|QL for charts that use a single Top values dimension, when “Group remaining values as Other” is turned off.

Generated query shape:

STATS <metric> BY <field>
| SORT <metric or field> <ASC|DESC>
| LIMIT <size>

Part of kibana-team#2889. Gates/tooltips for unsupported terms configs landed earlier in #289951.

What changed

  • Convert Top values → ES|QL for the single-bucket happy path
  • Rank by metric or alphabetical; respect size
  • Keep failing (with existing reasons) for Other, unsupported ranking, multi-field, multi-bucket, and time-series configs

Supported in this PR

Works when all of these are true:

  1. One bucket only, and it is Top values
  2. Other is off
  3. Rank by a metric or alphabetical (not rare / significant / custom)
  4. One field (no “+ other field”)
  5. No date histogram on the layer

Examples: pie/donut; bar with Top values as the only category; metric broken down by Top values only.

Testing dashboard: top-n.ndjson.zip

Remaining to close https://github.com/elastic/kibana-team/issues/2889

This PR does not fully close the issue. Still needed for the issue’s in-scope work:

Left Notes
Multi-bucket non-time-series (e.g. category + Break down by Top values, multi-dim table) Issue calls for LIMIT n BY <outer groups>
Unit tests for multi-dimension success paths Issue task
Decide min stack / LIMIT BY capability gate Issue task + open question (relevant once LIMIT BY ships)

Out of scope

Config Notes
Other on (default) Keep non-convertible; clear reason already
Top values + date histogram (time series) Separate follow-up outside this issue
Multi-terms beyond kibana#236682 Called out as out of scope on the issue

Still not convertible in this PR

Config Reason
Other on No ES|QL “Other” bucket
Rare / significant / custom rank No ES|QL equivalent (issue scope: metric + alphabetical only)
Multi-field Top values Out of issue scope
Include/exclude or accuracy mode Unsupported for conversion
Two+ buckets (breakdown / split / two Top values dims) Remaining #2889 work (LIMIT BY)
Top values + date histogram Out of issue scope

Test plan

  • Jest: generate_esql_query.top_n.test.ts
  • Manual: Other off on pie/bar → Convert succeeds
  • Manual: Other on → Convert disabled, Other tooltip
  • Manual: multi-bucket / breakdown → still disabled (expected until LIMIT BY follow-up)

@mariairiartef mariairiartef self-assigned this Sep 11, 2026
@mariairiartef mariairiartef added Team:Visualizations Team label for Lens, elastic-charts, Graph, legacy editors (TSVB, Visualize, Timelion) t// release_note:skip Skip the PR/issue when compiling release notes Feature:Lens backport:version Backport to applied version labels labels Sep 11, 2026
@mariairiartef mariairiartef changed the title Add top n support [Lens powered by ES|QL] Enable topN support (Other disabled) for non-time-series charts Sep 11, 2026
@mariairiartef

Copy link
Copy Markdown
Contributor Author

/ci

@mariairiartef

Copy link
Copy Markdown
Contributor Author

/ci

@mariairiartef
mariairiartef marked this pull request as ready for review September 14, 2026 14:33
@mariairiartef
mariairiartef requested a review from a team as a code owner September 14, 2026 14:33
@infra-vault-gh-plugin-prod

Copy link
Copy Markdown

Pinging @elastic/kibana-visualizations (Team:Visualizations)

@kibanamachine

Copy link
Copy Markdown
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Metrics [docs]

Unknown metric groups

shared async chunks total size

id before after diff
all 15.0MB 15.0MB +710.0B

total optimizer output size

id before after diff
all 63.9MB 63.9MB +710.0B

Test Failures

  • [job] [logs] Jest Tests #6 / CasesWebhookActionConnectorFields renders Step Validation Step 2 is properly validated
  • [job] [logs] Jest Tests #6 / CasesWebhookActionConnectorFields renders Step Validation Step 3 is properly validated
  • [job] [logs] FTR Configs #22 / lens app - group 2 lens layer actions tests should show visualization modifiers for layer settings when embedded in a dashboard
  • [job] [logs] Jest Tests #16 / StepAboutRuleComponent does not modify the provided risk score until the user changes the severity

History

cc @mariairiartef

@walterra walterra 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.

Code LGTM, tested locally including the limitations and disabled states, works great!

@mariairiartef
mariairiartef merged commit 7da0714 into elastic:main Sep 15, 2026
41 checks passed
@kibanamachine kibanamachine added backport:skip This PR does not require backporting v9.6.0 and removed backport:version Backport to applied version labels labels Sep 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting Feature:Lens release_note:skip Skip the PR/issue when compiling release notes Team:Visualizations Team label for Lens, elastic-charts, Graph, legacy editors (TSVB, Visualize, Timelion) t// v9.6.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants