Skip to content

Commit 409dbd5

Browse files
Disable sort optimization when index is sorted
Don't run long sort optimization when index is already sorted on the same field as the sort query parameter. Relates to elastic#37043, follow up for elastic#48804
1 parent fffba25 commit 409dbd5

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
@@ -412,6 +412,10 @@ private static Query tryRewriteLongSort(SearchContext searchContext, IndexReader
412412
if (searchContext.collapse() != null) return null;
413413
if (searchContext.trackScores()) return null;
414414
if (searchContext.aggregations() != null) return null;
415+
if (canEarlyTerminate(reader, searchContext.sort())) {
416+
// disable this optimization if index sorting matches the query sort since it's already optimized by index searcher
417+
return null;
418+
}
415419
Sort sort = searchContext.sort().sort;
416420
SortField sortField = sort.getSort()[0];
417421
if (SortField.Type.LONG.equals(IndexSortConfig.getSortFieldType(sortField)) == false) return null;

0 commit comments

Comments
 (0)