Skip to content

[9.5] [Discover] [ES|QL] fix: stats by previous aggregated field (#290259) - #290297

Merged
kibanamachine merged 1 commit into
elastic:9.5from
kibanamachine:backport/9.5/pr-290259
Sep 10, 2026
Merged

[9.5] [Discover] [ES|QL] fix: stats by previous aggregated field (#290259)#290297
kibanamachine merged 1 commit into
elastic:9.5from
kibanamachine:backport/9.5/pr-290259

Conversation

@kibanamachine

Copy link
Copy Markdown
Contributor

Backport

This will backport the following commits from main to 9.5:

Questions ?

Please refer to the Backport tool documentation

…90259)

- Closes elastic#290060
## Summary

Fixes an unhandled `TypeError: undefined is not an object (evaluating
'groupFieldNode.arg')` thrown by `getESQLStatsQueryMeta` (used by
Discover's ES|QL "cascade documents" breakdown feature) when a query has
two `STATS` commands and the second groups `BY` a field that the first
`STATS` declared as an **aggregate** alias rather than a `BY`-grouping
alias.

### Repro

```esql
FROM kibana_sample_data_logs
| STATS x = MAX(bytes)
| STATS c = COUNT(*) BY x
```

### Solution
`x` should be treated as a regular column, the code was incorrectly
branching into a special case as `x` was defined in the previous `STATS`
command (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
<img width="1724" height="945" alt="image"
src="https://github.com/user-attachments/assets/17ba47a5-84f3-48fc-b09f-bb6263d1ae07"
/>

#### After
<img width="1723" height="902" alt="image"
src="https://github.com/user-attachments/assets/c137f927-01e3-4705-8d0d-ad50663f08e0"
/>

### Checklist
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

(cherry picked from commit d5e1a4e)
@kibanamachine kibanamachine added the backport This PR is a backport of another PR label Sep 10, 2026
@kibanamachine
kibanamachine enabled auto-merge (squash) September 10, 2026 12:25
@kibanamachine

Copy link
Copy Markdown
Contributor Author

💛 Build succeeded, but was flaky

Failed CI Steps

Metrics [docs]

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
shared-packages 3.6MB 3.6MB +261.0B
Unknown metric groups

ESLint disabled line counts

id before after diff
@kbn/esql-utils 3 4 +1

Total ESLint disabled count

id before after diff
@kbn/esql-utils 3 4 +1

total optimizer output size

id before after diff
all 59.8MB 59.8MB +261.0B

Test Failures

  • [job] [logs] FTR Configs #9 / Cloud Security Posture - Group 1 (Rules) Cloud Posture Rules Page - Table Rules Page - Bulk Action buttons It should disable Disable option when there are all rules selected are already Disabled
  • [job] [logs] FTR Configs #38 / Index Management app Index Management: data streams tab Data streams tab data lifecycle flyout bulk edit modal allows to disable data retention
  • [job] [logs] FTR Configs #38 / Index Management app Index Management: data streams tab Data streams tab failure store (failed data lifecycle) allows to disable failure store from the details panel
  • [job] [logs] FTR Configs #38 / Index Management app Index Management: data streams tab Data streams tab failure store (failed data lifecycle) allows to enable failure store from the details panel
  • [job] [logs] FTR Configs #47 / maps app filter by map extent should filter dashboard by map extent when "filter by map extent" is enabled
  • [job] [logs] FTR Configs #47 / maps app filter by map extent should filter dashboard by new map extent when map is moved

cc @sddonne

@kibanamachine
kibanamachine merged commit 874dfb1 into elastic:9.5 Sep 10, 2026
59 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport This PR is a backport of another PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants