Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use search_after with field collapse #2935

Closed
jorge-marques opened this issue Jun 27, 2024 · 3 comments · Fixed by #2937
Closed

Cannot use search_after with field collapse #2935

jorge-marques opened this issue Jun 27, 2024 · 3 comments · Fixed by #2937
Labels
type: bug A general bug

Comments

@jorge-marques
Copy link

jorge-marques commented Jun 27, 2024

The elasticsearch documentation indicates that it is possible to use search_after with field collapse, as long the results are sorted exclusively by the collapsing field.

Is this possible with spring-data-elasticsearch? A cursory look at the code suggests it's not possible as _shard_doc is always added to the sort criteria as a tiebreaker

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 27, 2024
@sothawo
Copy link
Collaborator

sothawo commented Jun 28, 2024

I assume you are talking about calls to ReactiveSearchOperations.search(Query,...) as this is the only place where in the implementation search_after is used?

So you are setting a FieldCollapse on a NativeQuery and want to add a Sort for that same field and that fails then?

The solution would probably be to not add the shard_doc when there is a FieldCollapse set with a field name being the same as the one in the only Sort passed in.

@sothawo sothawo added status: waiting-for-feedback We need additional information before we can continue and removed status: waiting-for-triage An issue we've not yet triaged labels Jun 28, 2024
@jorge-marques
Copy link
Author

jorge-marques commented Jul 1, 2024

That's exactly right, elasticsearch returns the following error:
Cannot use [collapse] in conjunction with [search_after] unless the search is sorted on the same field. Multiple sort fields are not allowed

I believe your proposed solution would work well.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Jul 1, 2024
sothawo added a commit to sothawo/spring-data-elasticsearch that referenced this issue Jul 6, 2024
@sothawo sothawo closed this as completed in dd156b9 Jul 6, 2024
@sothawo sothawo added type: enhancement A general enhancement and removed status: feedback-provided Feedback has been provided labels Jul 6, 2024
@sothawo sothawo added this to the 5.4 M1 (2024.1.0) milestone Jul 6, 2024
@sothawo sothawo added type: bug A general bug and removed type: enhancement A general enhancement labels Jul 6, 2024
sothawo added a commit that referenced this issue Jul 6, 2024
Original Pull Request #2937
Closes #2935

(cherry picked from commit dd156b9)
@sothawo
Copy link
Collaborator

sothawo commented Jul 6, 2024

Implemented on main branch and backported to current 5.3.x.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants