Skip to content

Commit

Permalink
Add additional sorts to other locations
Browse files Browse the repository at this point in the history
Signed-off-by: Simeon Widdis <[email protected]>
  • Loading branch information
Swiddis committed Oct 10, 2024
1 parent a8af162 commit 3ba5a7e
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.opensearch.common.unit.TimeValue;
import org.opensearch.search.SearchHits;
import org.opensearch.search.builder.PointInTimeBuilder;
import org.opensearch.search.sort.SortOrder;
import org.opensearch.sql.legacy.domain.Select;
import org.opensearch.sql.legacy.esdomain.LocalClusterState;
import org.opensearch.sql.legacy.exception.SqlParseException;
Expand Down Expand Up @@ -70,6 +71,7 @@ public SearchResponse getResponseWithHits(
boolean ordered = select.isOrderdSelect();
if (!ordered) {
request.addSort(DOC_FIELD_NAME, ASC);
request.addSort("_id", SortOrder.ASC);
}
// Set PIT
request.setPointInTime(new PointInTimeBuilder(pit.getPitId()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public static SearchResponse scrollOneTimeWithHits(
boolean ordered = originalSelect.isOrderdSelect();
if (!ordered) {
scrollRequest.addSort(FieldSortBuilder.DOC_FIELD_NAME, SortOrder.ASC);
scrollRequest.addSort("_id", SortOrder.ASC);
}
SearchResponse responseWithHits = scrollRequest.get();
// on ordered select - not using SCAN , elastic returns hits on first scroll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public void checkAndSetScroll() {
boolean ordered = select.isOrderdSelect();
if (!ordered) {
request.addSort(FieldSortBuilder.DOC_FIELD_NAME, SortOrder.ASC);
request.addSort("_id", SortOrder.ASC);
}
// Request also requires PointInTime, but we should create pit while execution.
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ protected void loadFirstBatch() {
request
.getRequestBuilder()
.addSort(FieldSortBuilder.DOC_FIELD_NAME, SortOrder.ASC)
.addSort("_id", SortOrder.ASC)
.setSize(pageSize)
.setTimeout(TimeValue.timeValueSeconds(timeout))
.setPointInTime(new PointInTimeBuilder(pitId))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ protected void loadFirstBatch() {
request
.getRequestBuilder()
.addSort(FieldSortBuilder.DOC_FIELD_NAME, SortOrder.ASC)
.addSort("_id", SortOrder.ASC)
.setSize(pageSize)
.setScroll(TimeValue.timeValueSeconds(timeout))
.get();
Expand Down

0 comments on commit 3ba5a7e

Please sign in to comment.