Skip to content

Fix interim async search paging in CCS - #163290

Merged
reugn merged 3 commits into
elastic:mainfrom
perfloop-oss:fix/async-search-interim-pagination-agent
Nov 11, 2026
Merged

reugn merged 3 commits into
elastic:mainfrom
perfloop-oss:fix/async-search-interim-pagination-agent

Conversation

@perfloop-agent

@perfloop-agent perfloop-agent commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Closes #160954.

What goes wrong. An async cross-cluster search with ccs_minimize_roundtrips=true returns the wrong page while a remote cluster is still running. With from: 3 and size: 2, the interim response holds five local hits (local-0 to local-4) instead of local-3 and local-4. The final response is correct.

Cause. Before it sends the per-cluster searches, TransportSearchAction rewrites the shared search source to from: 0, size: from + size. The supplier that builds the merger for interim responses then reads the page from that rewritten source.

Change. The supplier now takes from, size and track_total_hits from the coordinating merger, which keeps the requested values. As on main, interim mergers get no circuit breaker.

Test. CrossClusterAsyncSearchIT.testCcsMinimizeRoundtripsIntermediateResultsUseRequestedPage blocks the remote query, checks the interim hit IDs, and then checks the final page. It fails on main without this change and passes with it. TransportSearchActionTests.testCCSRemoteReduce now also checks the interim merger's page and total-hits limit, with and without a local cluster.

./gradlew :x-pack:plugin:async-search:internalClusterTest \
  --tests org.elasticsearch.xpack.search.CrossClusterAsyncSearchIT.testCcsMinimizeRoundtripsIntermediateResultsUseRequestedPage
./gradlew :server:test --tests org.elasticsearch.action.search.TransportSearchActionTests

Found with Perfloop.

@cla-checker-service

cla-checker-service Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

💚 CLA has been signed

@elasticsearchmachine elasticsearchmachine added needs:triage Requires assignment of a team area label v9.7.0 external-contributor Pull request authored by a developer outside the Elasticsearch team labels Oct 25, 2026
@tsenart

tsenart commented Oct 25, 2026

Copy link
Copy Markdown

Hi, I'm Tomás, I build Perfloop. I approved this contribution and will handle review feedback here.

We've had performance PRs merged in ClickHouse, Prometheus, Ruff/ty, parquet-go, RoaringBitmap, and more.

@tsenart
tsenart force-pushed the fix/async-search-interim-pagination-agent branch from 6f83eb5 to 21c2728 Compare November 4, 2026 12:23
@elasticsearchmachine elasticsearchmachine added Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch and removed needs:triage Requires assignment of a team area label labels Nov 4, 2026
@elasticsearchmachine

Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-search-infra (Team:Search Foundations)

@tsenart

tsenart commented Nov 6, 2026

Copy link
Copy Markdown

@reugn: Thanks again for your review on #160955. This PR replaces it and covers both of your points: it adds docs/changelog/163290.yaml, and TransportSearchActionTests.testCCSRemoteReduce now checks the interim merger's from, size and total-hits limit, with and without a local cluster. Could you take another look?

@reugn reugn self-assigned this Nov 10, 2026
@reugn reugn added the >bug label Nov 10, 2026
@reugn

reugn commented Nov 10, 2026

Copy link
Copy Markdown
Member

buildkite test this

@reugn reugn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for fixing this, @tsenart.

@reugn
reugn merged commit e93c8ff into elastic:main Nov 11, 2026
44 checks passed
elasticsearchmachine pushed a commit that referenced this pull request Nov 11, 2026
An async cross-cluster search with ccs_minimize_roundtrips=true returned extra hits in interim responses when from was greater than 0. Before it sends the per-cluster searches, the coordinator rewrites the shared search source to from: 0 and size: from + size. The supplier that builds the interim merger read the page from that rewritten source, so interim responses returned the whole widened window instead of the requested page. The final response was always correct. The supplier now takes from, size and track_total_hits from the first merger, which keeps the requested values.

(cherry picked from commit e93c8ff)

Co-authored-by: Perfloop Agent <[email protected]>
elasticsearchmachine pushed a commit that referenced this pull request Nov 11, 2026
An async cross-cluster search with ccs_minimize_roundtrips=true returned extra hits in interim responses when from was greater than 0. Before it sends the per-cluster searches, the coordinator rewrites the shared search source to from: 0 and size: from + size. The supplier that builds the interim merger read the page from that rewritten source, so interim responses returned the whole widened window instead of the requested page. The final response was always correct. The supplier now takes from, size and track_total_hits from the first merger, which keeps the requested values.

(cherry picked from commit e93c8ff)

Co-authored-by: Perfloop Agent <[email protected]>
elasticsearchmachine pushed a commit that referenced this pull request Nov 11, 2026
An async cross-cluster search with ccs_minimize_roundtrips=true returned extra hits in interim responses when from was greater than 0. Before it sends the per-cluster searches, the coordinator rewrites the shared search source to from: 0 and size: from + size. The supplier that builds the interim merger read the page from that rewritten source, so interim responses returned the whole widened window instead of the requested page. The final response was always correct. The supplier now takes from, size and track_total_hits from the first merger, which keeps the requested values.

(cherry picked from commit e93c8ff)

Co-authored-by: Perfloop Agent <[email protected]>
sarog pushed a commit to portsbuild/elasticsearch that referenced this pull request Nov 24, 2026
An async cross-cluster search with ccs_minimize_roundtrips=true returned extra hits in interim responses when from was greater than 0. Before it sends the per-cluster searches, the coordinator rewrites the shared search source to from: 0 and size: from + size. The supplier that builds the interim merger read the page from that rewritten source, so interim responses returned the whole widened window instead of the requested page. The final response was always correct. The supplier now takes from, size and track_total_hits from the first merger, which keeps the requested values.

(cherry picked from commit e93c8ff)

Co-authored-by: Perfloop Agent <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>bug external-contributor Pull request authored by a developer outside the Elasticsearch team :Search Foundations/CCS Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch v8.19.26 v9.5.7 v9.6.1 v9.7.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Async CCS interim results ignore requested paging

5 participants