Skip to content

ESQL: Adds GroupedTopN command#140019

Closed
ncordon wants to merge 149 commits intoelastic:mainfrom
ncordon:grouped_topn
Closed

ESQL: Adds GroupedTopN command#140019
ncordon wants to merge 149 commits intoelastic:mainfrom
ncordon:grouped_topn

Conversation

@ncordon
Copy link
Copy Markdown
Member

@ncordon ncordon commented Dec 29, 2025

Addresses #112918

Adds a LIMIT BY ESQL command, i.e.

FROM test
| SORT salary DESC
| LIMIT 5 BY languages
| KEEP first_name, last_name, salary, languages

This query would give us the 5 employees with the highest salary per number of languages they speak (i.e. 5 employees with the highest salaries that speak 3 languages, 5 employees with the highest salaries that speak 2 languages, etc)

@ncordon ncordon added Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) :Analytics/ES|QL AKA ESQL >enhancement labels Dec 29, 2025
@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

Hi @ncordon, I've created a changelog YAML for you.

@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

Hi @ncordon, I've updated the changelog YAML for you.

@ncordon ncordon force-pushed the grouped_topn branch 2 times, most recently from ce838fe to 451b668 Compare December 29, 2025 13:46
ivancea and others added 11 commits February 26, 2026 13:17
# Conflicts:
#	server/src/main/resources/transport/upper_bounds/9.4.csv
#	x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/operator/topn/TopNOperatorTests.java
#	x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/planner/LocalExecutionPlanner.java
# Conflicts:
#	x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/parser/EsqlBaseParser.interp
#	x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/parser/EsqlBaseParser.java
ivancea added 2 commits March 4, 2026 12:28
# Conflicts:
#	server/src/main/resources/transport/upper_bounds/9.4.csv
#	x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/optimizer/rules/physical/local/golden_tests/SubstituteRoundToGoldenTests/testDateTruncNotTransformToQueryAndTags/date_trunc/local_physical_optimization.expected
#	x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/optimizer/rules/physical/local/golden_tests/SubstituteRoundToGoldenTests/testDateTruncNotTransformToQueryAndTags/round_to/local_physical_optimization.expected
Comment on lines +43 to +44
// Rationale: both GROUP BY and LIMIT BY explode multi-value fields into single values.
// For example:
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not true anymore, we need to change this

ivancea added a commit that referenced this pull request Mar 10, 2026
ivancea and others added 6 commits March 11, 2026 14:57
# Conflicts:
#	server/src/main/resources/transport/upper_bounds/9.4.csv
#	x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/operator/topn/GroupedQueue.java
#	x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/operator/topn/GroupedTopNOperator.java
#	x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/operator/topn/GroupedTopNOperatorStatus.java
#	x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/operator/topn/GroupedQueueTests.java
#	x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/operator/topn/GroupedTopNOperatorStatusTests.java
#	x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/operator/topn/GroupedTopNOperatorTests.java
#	x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/operator/topn/TopNOperatorTests.java
#	x-pack/plugin/esql/compute/test/src/main/java/org/elasticsearch/compute/test/operator/blocksource/ListRowsBlockSourceOperator.java
#	x-pack/plugin/esql/compute/test/src/main/java/org/elasticsearch/compute/test/operator/blocksource/TupleAbstractBlockSourceOperator.java
#	x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/optimizer/LogicalPlanOptimizer.java
#	x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/parser/EsqlBaseParser.interp
#	x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/parser/EsqlBaseParser.java
#	x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/LogicalPlanOptimizerTests.java
# Conflicts:
#	server/src/main/resources/transport/upper_bounds/9.4.csv
#	x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/LogicalPlanOptimizerTests.java
# Conflicts:
#	x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/parser/LogicalPlanBuilder.java
#	x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/parser/StatementParserTests.java
@ncordon ncordon closed this Mar 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Analytics/ES|QL AKA ESQL >feature Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v9.4.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants