Skip to content

Commit

Permalink
Disable sort optimization when index is sorted
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mayya-sharipova committed Nov 29, 2019
1 parent fffba25 commit 409dbd5
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,10 @@ private static Query tryRewriteLongSort(SearchContext searchContext, IndexReader
if (searchContext.collapse() != null) return null;
if (searchContext.trackScores()) return null;
if (searchContext.aggregations() != null) return null;
if (canEarlyTerminate(reader, searchContext.sort())) {
// disable this optimization if index sorting matches the query sort since it's already optimized by index searcher
return null;
}
Sort sort = searchContext.sort().sort;
SortField sortField = sort.getSort()[0];
if (SortField.Type.LONG.equals(IndexSortConfig.getSortFieldType(sortField)) == false) return null;
Expand Down

0 comments on commit 409dbd5

Please sign in to comment.