Skip to content

Conversation

@gaobinlong
Copy link
Contributor

@gaobinlong gaobinlong commented Sep 9, 2025

Description

Why field collapsing doesn't support pagination by search_after? The reason is that if we collapse and sort on different field, and use search_after to fetch next page, the same collapsed key may show again in the next page, see the example blow:
image

Now we collapse on session_id and sort by timestamp ascending, the first page would be:

  • s1 - /page1 - 2025-09-07T10:00:00
  • s2 - /home - 2025-09-07T10:02:00

, then paging with search_after, the second page would be:

  • s2 - /contact - 2025-09-07T10:07:00
  • s1 - /page2 - 2025-09-07T10:05:00

, the above behavior would break the field collapsing, but we could imagine that if we collapse and sort on same filed, search_after will work.

So this PR adds the search_after support for field collapsing, but limit the usage that collapse field and sort field must be the same and secondary sort is not supported.

Related Issues

Resolves #3725

Check List

  • Functionality includes testing.
  • API changes companion pull request created, if applicable.
  • Public documentation issue/PR created, if applicable.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@github-actions
Copy link
Contributor

github-actions bot commented Sep 9, 2025

❌ Gradle check result for 9dc634d: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Signed-off-by: Binlong Gao <[email protected]>
@github-actions
Copy link
Contributor

github-actions bot commented Sep 9, 2025

❌ Gradle check result for a876128: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@gaobinlong
Copy link
Contributor Author

Hi @reta @andrross , could you help to review this PR, thanks!

@reta
Copy link
Contributor

reta commented Sep 11, 2025

Hi @reta @andrross , could you help to review this PR, thanks!

Apologies for the delay, @gaobinlong , I will take a look today / tomorrow, thank you

@reta
Copy link
Contributor

reta commented Sep 13, 2025

Thanks a lot @gaobinlong , a few minor comments but LGTM otherwise, apologies for the delay

@github-actions
Copy link
Contributor

❌ Gradle check result for ea9fd6b: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Signed-off-by: Binlong Gao <[email protected]>
@github-actions
Copy link
Contributor

❌ Gradle check result for fbf7a77: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@github-actions
Copy link
Contributor

❌ Gradle check result for fbf7a77: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Signed-off-by: Binlong Gao <[email protected]>
@github-actions
Copy link
Contributor

❌ Gradle check result for 62767e6: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@github-actions
Copy link
Contributor

❌ Gradle check result for 62767e6: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@github-actions
Copy link
Contributor

✅ Gradle check result for 62767e6: SUCCESS

@codecov
Copy link

codecov bot commented Sep 17, 2025

Codecov Report

❌ Patch coverage is 77.55102% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.88%. Comparing base (a3ac746) to head (62767e6).
⚠️ Report is 10 commits behind head on main.

Files with missing lines Patch % Lines
...rg/opensearch/search/collapse/CollapseContext.java 20.00% 2 Missing and 2 partials ⚠️
...main/java/org/opensearch/search/SearchService.java 0.00% 3 Missing ⚠️
...ne/search/grouping/CollapsingTopDocsCollector.java 93.75% 0 Missing and 2 partials ⚠️
...ensearch/search/query/TopDocsCollectorContext.java 77.77% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main   #19261      +/-   ##
============================================
- Coverage     72.89%   72.88%   -0.01%     
- Complexity    69763    69765       +2     
============================================
  Files          5667     5667              
  Lines        320547   320590      +43     
  Branches      46348    46357       +9     
============================================
+ Hits         233648   233654       +6     
- Misses        68005    68038      +33     
- Partials      18894    18898       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@gaobinlong gaobinlong merged commit b856451 into opensearch-project:main Sep 17, 2025
33 of 37 checks passed
jainankitk pushed a commit to jainankitk/OpenSearch that referenced this pull request Sep 22, 2025
* Field collapsing supports search_after

Signed-off-by: Binlong Gao <[email protected]>

* Modify change log

Signed-off-by: Binlong Gao <[email protected]>

* Avoid changing public APIs

Signed-off-by: Binlong Gao <[email protected]>

* Revert change for the existing method

Signed-off-by: Binlong Gao <[email protected]>

* Format change log

Signed-off-by: Binlong Gao <[email protected]>

* Fix some issues

Signed-off-by: Binlong Gao <[email protected]>

* Remove duplicate code

Signed-off-by: Binlong Gao <[email protected]>

* Fix format issue

Signed-off-by: Binlong Gao <[email protected]>

---------

Signed-off-by: Binlong Gao <[email protected]>
jainankitk pushed a commit to jainankitk/OpenSearch that referenced this pull request Sep 22, 2025
* Field collapsing supports search_after

Signed-off-by: Binlong Gao <[email protected]>

* Modify change log

Signed-off-by: Binlong Gao <[email protected]>

* Avoid changing public APIs

Signed-off-by: Binlong Gao <[email protected]>

* Revert change for the existing method

Signed-off-by: Binlong Gao <[email protected]>

* Format change log

Signed-off-by: Binlong Gao <[email protected]>

* Fix some issues

Signed-off-by: Binlong Gao <[email protected]>

* Remove duplicate code

Signed-off-by: Binlong Gao <[email protected]>

* Fix format issue

Signed-off-by: Binlong Gao <[email protected]>

---------

Signed-off-by: Binlong Gao <[email protected]>
Signed-off-by: Ankit Jain <[email protected]>
jainankitk pushed a commit to jainankitk/OpenSearch that referenced this pull request Sep 22, 2025
* Field collapsing supports search_after

Signed-off-by: Binlong Gao <[email protected]>

* Modify change log

Signed-off-by: Binlong Gao <[email protected]>

* Avoid changing public APIs

Signed-off-by: Binlong Gao <[email protected]>

* Revert change for the existing method

Signed-off-by: Binlong Gao <[email protected]>

* Format change log

Signed-off-by: Binlong Gao <[email protected]>

* Fix some issues

Signed-off-by: Binlong Gao <[email protected]>

* Remove duplicate code

Signed-off-by: Binlong Gao <[email protected]>

* Fix format issue

Signed-off-by: Binlong Gao <[email protected]>

---------

Signed-off-by: Binlong Gao <[email protected]>
Signed-off-by: Ankit Jain <[email protected]>
asimmahmood1 pushed a commit to jainankitk/OpenSearch that referenced this pull request Sep 23, 2025
* Field collapsing supports search_after

Signed-off-by: Binlong Gao <[email protected]>

* Modify change log

Signed-off-by: Binlong Gao <[email protected]>

* Avoid changing public APIs

Signed-off-by: Binlong Gao <[email protected]>

* Revert change for the existing method

Signed-off-by: Binlong Gao <[email protected]>

* Format change log

Signed-off-by: Binlong Gao <[email protected]>

* Fix some issues

Signed-off-by: Binlong Gao <[email protected]>

* Remove duplicate code

Signed-off-by: Binlong Gao <[email protected]>

* Fix format issue

Signed-off-by: Binlong Gao <[email protected]>

---------

Signed-off-by: Binlong Gao <[email protected]>
pranikum pushed a commit to pranikum/OpenSearch that referenced this pull request Sep 23, 2025
* Field collapsing supports search_after

Signed-off-by: Binlong Gao <[email protected]>

* Modify change log

Signed-off-by: Binlong Gao <[email protected]>

* Avoid changing public APIs

Signed-off-by: Binlong Gao <[email protected]>

* Revert change for the existing method

Signed-off-by: Binlong Gao <[email protected]>

* Format change log

Signed-off-by: Binlong Gao <[email protected]>

* Fix some issues

Signed-off-by: Binlong Gao <[email protected]>

* Remove duplicate code

Signed-off-by: Binlong Gao <[email protected]>

* Fix format issue

Signed-off-by: Binlong Gao <[email protected]>

---------

Signed-off-by: Binlong Gao <[email protected]>
vinaykpud pushed a commit to vinaykpud/OpenSearch that referenced this pull request Sep 26, 2025
* Field collapsing supports search_after

Signed-off-by: Binlong Gao <[email protected]>

* Modify change log

Signed-off-by: Binlong Gao <[email protected]>

* Avoid changing public APIs

Signed-off-by: Binlong Gao <[email protected]>

* Revert change for the existing method

Signed-off-by: Binlong Gao <[email protected]>

* Format change log

Signed-off-by: Binlong Gao <[email protected]>

* Fix some issues

Signed-off-by: Binlong Gao <[email protected]>

* Remove duplicate code

Signed-off-by: Binlong Gao <[email protected]>

* Fix format issue

Signed-off-by: Binlong Gao <[email protected]>

---------

Signed-off-by: Binlong Gao <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Enhancement or improvement to existing feature or request feature New feature or request Indexing & Search

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support field collapsing with search_after

2 participants