Skip to content

Commit ce9f792

Browse files
committed
Get max value for LeafReader sorting from docvalues skipper
1 parent bd40507 commit ce9f792

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

server/src/main/java/org/elasticsearch/cluster/metadata/DataStream.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
package org.elasticsearch.cluster.metadata;
1010

1111
import org.apache.lucene.document.LongPoint;
12+
import org.apache.lucene.index.DocValuesSkipIndexType;
13+
import org.apache.lucene.index.DocValuesSkipper;
14+
import org.apache.lucene.index.FieldInfo;
1215
import org.apache.lucene.index.LeafReader;
1316
import org.apache.lucene.index.PointValues;
1417
import org.elasticsearch.ElasticsearchException;
@@ -84,6 +87,12 @@ public static boolean isFailureStoreFeatureFlagEnabled() {
8487
// Timeseries indices' leaf readers should be sorted by desc order of their timestamp field, as it allows search time optimizations
8588
public static final Comparator<LeafReader> TIMESERIES_LEAF_READERS_SORTER = Comparator.comparingLong((LeafReader r) -> {
8689
try {
90+
FieldInfo info = r.getFieldInfos().fieldInfo(TIMESTAMP_FIELD_NAME);
91+
if (info.docValuesSkipIndexType() == DocValuesSkipIndexType.RANGE) {
92+
DocValuesSkipper skipper = r.getDocValuesSkipper(TIMESTAMP_FIELD_NAME);
93+
return skipper.maxValue();
94+
}
95+
8796
PointValues points = r.getPointValues(TIMESTAMP_FIELD_NAME);
8897
if (points != null) {
8998
byte[] sortValue = points.getMaxPackedValue();

0 commit comments

Comments
 (0)