[Discover] [ES|QL] fix: stats by previous aggregated field - #290259
Merged
sddonne merged 2 commits intoSep 10, 2026
Conversation
Contributor
💚 Build Succeeded
Metrics [docs]Page load bundle
Unknown metric groupsESLint disabled line counts
Total ESLint disabled count
total optimizer output size
warm start memory
cc @sddonne |
sddonne
marked this pull request as ready for review
September 10, 2026 11:14
|
Pinging @elastic/kibana-data-discovery (Team:DataDiscovery) |
|
Pinging @elastic/kibana-esql (Team:ESQL) |
stratoula
approved these changes
Sep 10, 2026
stratoula
left a comment
Contributor
There was a problem hiding this comment.
Code review only, LGTM!
| * This method will exclude queries contain commands that are not valid for the cascade experience, | ||
| */ | ||
| export const getESQLStatsQueryMeta = (queryString: string): ESQLStatsQueryMeta => { | ||
| try { |
Contributor
|
Starting backport for target branches: 9.5 |
Contributor
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
kibanamachine
added a commit
that referenced
this pull request
Sep 10, 2026
…0259) (#290297) # Backport This will backport the following commits from `main` to `9.5`: - [[Discover] [ES|QL] fix: stats by previous aggregated field (#290259)](#290259) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Sebastian Delle Donne","email":"sebastian.delledonne@elastic.co"},"sourceCommit":{"committedDate":"2026-09-10T11:59:28Z","message":"[Discover] [ES|QL] fix: stats by previous aggregated field (#290259)\n\n- Closes https://github.com/elastic/kibana/issues/290060\n## Summary\n\nFixes an unhandled `TypeError: undefined is not an object (evaluating\n'groupFieldNode.arg')` thrown by `getESQLStatsQueryMeta` (used by\nDiscover's ES|QL \"cascade documents\" breakdown feature) when a query has\ntwo `STATS` commands and the second groups `BY` a field that the first\n`STATS` declared as an **aggregate** alias rather than a `BY`-grouping\nalias.\n\n### Repro\n\n```esql\nFROM kibana_sample_data_logs\n| STATS x = MAX(bytes)\n| STATS c = COUNT(*) BY x\n```\n\n### Solution\n`x` should be treated as a regular column, the code was incorrectly\nbranching into a special case as `x` was defined in the previous `STATS`\ncommand (expecting to be found as new group definition).\nAlso added a catch to avoid buggy UI when analysing the query fails,\n(discover was held in a permanent loading state before the fix)\n\n#### Before\n<img width=\"1724\" height=\"945\" alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/17ba47a5-84f3-48fc-b09f-bb6263d1ae07\"\n/>\n\n#### After\n<img width=\"1723\" height=\"902\" alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/c137f927-01e3-4705-8d0d-ad50663f08e0\"\n/>\n\n\n\n### Checklist\n- [x] [Unit or functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere updated or added to match the most common scenarios","sha":"d5e1a4e37970834570aaa52d0488081ded16123c","branchLabelMapping":{"^v9.6.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Discover","release_note:fix","Team:DataDiscovery","Team:ESQL","backport:version","v9.6.0","v9.5.5"],"title":"[Discover] [ES|QL] fix: stats by previous aggregated field","number":290259,"url":"https://github.com/elastic/kibana/pull/290259","mergeCommit":{"message":"[Discover] [ES|QL] fix: stats by previous aggregated field (#290259)\n\n- Closes https://github.com/elastic/kibana/issues/290060\n## Summary\n\nFixes an unhandled `TypeError: undefined is not an object (evaluating\n'groupFieldNode.arg')` thrown by `getESQLStatsQueryMeta` (used by\nDiscover's ES|QL \"cascade documents\" breakdown feature) when a query has\ntwo `STATS` commands and the second groups `BY` a field that the first\n`STATS` declared as an **aggregate** alias rather than a `BY`-grouping\nalias.\n\n### Repro\n\n```esql\nFROM kibana_sample_data_logs\n| STATS x = MAX(bytes)\n| STATS c = COUNT(*) BY x\n```\n\n### Solution\n`x` should be treated as a regular column, the code was incorrectly\nbranching into a special case as `x` was defined in the previous `STATS`\ncommand (expecting to be found as new group definition).\nAlso added a catch to avoid buggy UI when analysing the query fails,\n(discover was held in a permanent loading state before the fix)\n\n#### Before\n<img width=\"1724\" height=\"945\" alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/17ba47a5-84f3-48fc-b09f-bb6263d1ae07\"\n/>\n\n#### After\n<img width=\"1723\" height=\"902\" alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/c137f927-01e3-4705-8d0d-ad50663f08e0\"\n/>\n\n\n\n### Checklist\n- [x] [Unit or functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere updated or added to match the most common scenarios","sha":"d5e1a4e37970834570aaa52d0488081ded16123c"}},"sourceBranch":"main","suggestedTargetBranches":["9.5"],"targetPullRequestStates":[{"branch":"main","label":"v9.6.0","branchLabelMappingKey":"^v9.6.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/290259","number":290259,"mergeCommit":{"message":"[Discover] [ES|QL] fix: stats by previous aggregated field (#290259)\n\n- Closes https://github.com/elastic/kibana/issues/290060\n## Summary\n\nFixes an unhandled `TypeError: undefined is not an object (evaluating\n'groupFieldNode.arg')` thrown by `getESQLStatsQueryMeta` (used by\nDiscover's ES|QL \"cascade documents\" breakdown feature) when a query has\ntwo `STATS` commands and the second groups `BY` a field that the first\n`STATS` declared as an **aggregate** alias rather than a `BY`-grouping\nalias.\n\n### Repro\n\n```esql\nFROM kibana_sample_data_logs\n| STATS x = MAX(bytes)\n| STATS c = COUNT(*) BY x\n```\n\n### Solution\n`x` should be treated as a regular column, the code was incorrectly\nbranching into a special case as `x` was defined in the previous `STATS`\ncommand (expecting to be found as new group definition).\nAlso added a catch to avoid buggy UI when analysing the query fails,\n(discover was held in a permanent loading state before the fix)\n\n#### Before\n<img width=\"1724\" height=\"945\" alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/17ba47a5-84f3-48fc-b09f-bb6263d1ae07\"\n/>\n\n#### After\n<img width=\"1723\" height=\"902\" alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/c137f927-01e3-4705-8d0d-ad50663f08e0\"\n/>\n\n\n\n### Checklist\n- [x] [Unit or functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere updated or added to match the most common scenarios","sha":"d5e1a4e37970834570aaa52d0488081ded16123c"}},{"branch":"9.5","label":"v9.5.5","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Sebastian Delle Donne <sebastian.delledonne@elastic.co>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes an unhandled
TypeError: undefined is not an object (evaluating 'groupFieldNode.arg')thrown bygetESQLStatsQueryMeta(used by Discover's ES|QL "cascade documents" breakdown feature) when a query has twoSTATScommands and the second groupsBYa field that the firstSTATSdeclared as an aggregate alias rather than aBY-grouping alias.Repro
Solution
xshould be treated as a regular column, the code was incorrectly branching into a special case asxwas defined in the previousSTATScommand (expecting to be found as new group definition).Also added a catch to avoid buggy UI when analysing the query fails, (discover was held in a permanent loading state before the fix)
Before
After
Checklist