Skip to content

Commit

Permalink
Handle _shard_doc field for sort optimization (#69321)
Browse files Browse the repository at this point in the history
This commit ensures that the automatic tiebreaker `_shard_doc` does
not disable sort optimization.

Relates #56828
  • Loading branch information
jimczi committed Feb 22, 2021
1 parent 93b888e commit bd4a585
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import org.elasticsearch.search.profile.SearchProfileShardResults;
import org.elasticsearch.search.profile.query.InternalProfileCollector;
import org.elasticsearch.search.rescore.RescorePhase;
import org.elasticsearch.search.sort.FieldSortBuilder;
import org.elasticsearch.search.sort.SortAndFormats;
import org.elasticsearch.search.suggest.SuggestPhase;
import org.elasticsearch.tasks.TaskCancelledException;
Expand Down Expand Up @@ -428,10 +429,14 @@ private static Query tryRewriteLongSort(SearchContext searchContext, IndexReader
SortField sField = sort.getSort()[i];
String sFieldName = sField.getField();
if (sFieldName == null) {
if (SortField.FIELD_DOC.equals(sField) == false) return null;
} else {
if (SortField.FIELD_DOC.equals(sField) == false) {
return null;
}
} else if (FieldSortBuilder.SHARD_DOC_FIELD_NAME.equals(sFieldName) == false) {
//TODO: find out how to cover _script sort that don't use _score
if (searchExecutionContext.getFieldType(sFieldName) == null) return null; // could be _script sort that uses _score
if (searchExecutionContext.getFieldType(sFieldName) == null) {
return null; // could be _script sort that uses _score
}
}
}

Expand Down

0 comments on commit bd4a585

Please sign in to comment.