Skip to content

Potentially broken sorting in unbounded queries built with NativeQueryBuilder #2745

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

Closed
jorge-marques opened this issue Oct 23, 2023 · 1 comment · Fixed by #2746
Closed
Labels
type: bug A general bug

Comments

@jorge-marques
Copy link

jorge-marques commented Oct 23, 2023

My team is using the withSort(Function<SortOptions.Builder, ObjectBuilder<SortOptions>> fn) method in NativeQueryBuilder to include sort criteria for an unbounded query. This sets the sortOptions field when the query is built.

When the query is executed, the current implementation of doFindUnbounded in ReactiveElasticsearchTemplate calls addSort on the built query with Sort.by("_shard_doc") as the argument. This results in both sort and sortOptions being set, with sort having precedence when the query object is converted to JSON, breaking the expected result order.

We're on 5.1.4

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Oct 23, 2023
@jorge-marques jorge-marques changed the title Broken sorting in unbounded queries built with NativeQueryBuilder Potentially broken sorting in unbounded queries built with NativeQueryBuilder Oct 23, 2023
@sothawo sothawo added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Oct 23, 2023
sothawo added a commit to sothawo/spring-data-elasticsearch that referenced this issue Oct 23, 2023
sothawo added a commit that referenced this issue Oct 23, 2023
Original Pull Request #2746
Closes #2745
@sothawo sothawo added this to the 5.2 GA (2023.1.0) milestone Oct 23, 2023
sothawo added a commit that referenced this issue Oct 23, 2023
Original Pull Request #2746
Closes #2745

(cherry picked from commit 73fe086)
sothawo added a commit that referenced this issue Oct 23, 2023
Original Pull Request #2746
Closes #2745

(cherry picked from commit 73fe086)
(cherry picked from commit 2c85717)
@sothawo
Copy link
Collaborator

sothawo commented Oct 23, 2023

backported to branches 5.1 and 5.0

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