Skip to content

Commit 3bbaa01

Browse files
Disable sort optimization when index is sorted (#49727)
Don't run long sort optimization when index is already sorted on the same field as the sort query parameter. Relates to #37043, follow up for #48804
1 parent ad274dd commit 3bbaa01

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

server/src/main/java/org/elasticsearch/search/query/QueryPhase.java

+4
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,10 @@ private static Query tryRewriteLongSort(SearchContext searchContext, IndexReader
413413
if (searchContext.collapse() != null) return null;
414414
if (searchContext.trackScores()) return null;
415415
if (searchContext.aggregations() != null) return null;
416+
if (canEarlyTerminate(reader, searchContext.sort())) {
417+
// disable this optimization if index sorting matches the query sort since it's already optimized by index searcher
418+
return null;
419+
}
416420
Sort sort = searchContext.sort().sort;
417421
SortField sortField = sort.getSort()[0];
418422
if (SortField.Type.LONG.equals(IndexSortConfig.getSortFieldType(sortField)) == false) return null;

0 commit comments

Comments
 (0)