Skip to content

Add support for TopN and aggregation pushdown in Elasticsearch#27251

Open
bvolpato wants to merge 8 commits intotrinodb:masterfrom
bvolpato:bruno.volpato/es-pushdown-topn-aggregation-rebase
Open

Add support for TopN and aggregation pushdown in Elasticsearch#27251
bvolpato wants to merge 8 commits intotrinodb:masterfrom
bvolpato:bruno.volpato/es-pushdown-topn-aggregation-rebase

Conversation

@bvolpato
Copy link
Member

Description

This PR adds support for TopN, Limit, and Aggregation pushdown to the Elasticsearch connector, improving query performance by leveraging Elasticsearch's native sorting and aggregation capabilities.

TopN and Limit operations are pushed down to each shard, with Trino merging the results to ensure correct global ordering. Aggregation pushdown supports GROUP BY with COUNT, SUM, AVG, MIN, and MAX functions using Elasticsearch's composite and metric aggregations.

Additional context and related issues

This work was previously contributed by @murthy-chelankuri at #16919 and #23118 and I've rebased/fixed the conflicts and revisited the test cases.

Release notes

( ) This is not user-visible or is docs only, and no release notes are required.
(x) Release notes are required. Please propose a release note for me.
( ) Release notes are required, with the following suggested text:

# Fixes
* Support for order by pushdown in Elasticsearch connector #12381 
* Elasticsearch connector aggregation push down support #7026 
* Elasticsearch connector TopN pushdown #4803 

@cla-bot cla-bot bot added the cla-signed label Nov 10, 2025
@github-actions github-actions bot added the elasticsearch Elasticsearch connector label Nov 10, 2025
@bvolpato-dd bvolpato-dd force-pushed the bruno.volpato/es-pushdown-topn-aggregation-rebase branch from b227561 to b2472b3 Compare November 10, 2025 04:07
@bvolpato bvolpato marked this pull request as ready for review November 10, 2025 04:30
@bvolpato-dd bvolpato-dd force-pushed the bruno.volpato/es-pushdown-topn-aggregation-rebase branch from 6835e1b to aa1ab91 Compare November 16, 2025 03:44
@github-actions github-actions bot added the docs label Nov 16, 2025
@bvolpato
Copy link
Member Author

CI failure seems to be a flake:

Error:  Failed to execute goal com.github.eirslett:frontend-maven-plugin:1.15.4:npm (package (webapp)) on project trino-web-ui: Failed to run task: 'npm run package:clean' failed. org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1) -> [Help 1]

@bvolpato bvolpato force-pushed the bruno.volpato/es-pushdown-topn-aggregation-rebase branch from 2a5667c to e6445de Compare November 20, 2025 00:33
@bvolpato-dd bvolpato-dd force-pushed the bruno.volpato/es-pushdown-topn-aggregation-rebase branch from e6445de to c3b0dc3 Compare November 20, 2025 19:18
@github-actions
Copy link

This pull request has gone a while without any activity. Ask for help on #core-dev on Trino slack.

@github-actions github-actions bot added the stale label Dec 12, 2025
@github-actions
Copy link

github-actions bot commented Jan 2, 2026

Closing this pull request, as it has been stale for six weeks. Feel free to re-open at any time.

@github-actions github-actions bot closed this Jan 2, 2026
@bvolpato
Copy link
Member Author

bvolpato commented Jan 2, 2026

I'd be interested in taking this forward. Any takers for reviewing? 👀

@bvolpato bvolpato reopened this Jan 2, 2026
@bvolpato bvolpato force-pushed the bruno.volpato/es-pushdown-topn-aggregation-rebase branch from c3b0dc3 to df792eb Compare January 2, 2026 19:46
@github-actions github-actions bot removed the stale label Jan 5, 2026
@github-actions
Copy link

This pull request has gone a while without any activity. Ask for help on #core-dev on Trino slack.

@github-actions github-actions bot added the stale label Jan 26, 2026
.toArray(BlockBuilder[]::new);
this.queryBuilder = buildSearchQuery(table.constraint().transformKeys(ElasticsearchColumnHandle.class::cast), table.query(), table.regexes());

long start = System.nanoTime();
Copy link
Contributor

Choose a reason for hiding this comment

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

do we needs this here, or move this line up?

if (!newRegexes.containsKey(columnName) && pattern instanceof Slice slice) {
IndexMetadata metadata = client.getIndexMetadata(handle.index());
if (metadata.schema()
.fields().stream()
Copy link
Contributor

Choose a reason for hiding this comment

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

revert the change

@chenjian2664
Copy link
Contributor

@Praveen2112 @findepi you might be more familiar with Elasticsearch :)

@github-actions github-actions bot removed the stale label Feb 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed docs elasticsearch Elasticsearch connector

Development

Successfully merging this pull request may close these issues.

2 participants