Skip to content

Commit bd40507

Browse files
committed
Get min/max timestamp from DocValuesSkipper if enabled
1 parent 7cd7974 commit bd40507

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

server/src/main/java/org/elasticsearch/common/lucene/uid/PerThreadIDVersionAndSeqNoLookup.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
package org.elasticsearch.common.lucene.uid;
1111

1212
import org.apache.lucene.document.LongPoint;
13+
import org.apache.lucene.index.DocValuesSkipIndexType;
14+
import org.apache.lucene.index.DocValuesSkipper;
15+
import org.apache.lucene.index.FieldInfo;
1316
import org.apache.lucene.index.LeafReader;
1417
import org.apache.lucene.index.LeafReaderContext;
1518
import org.apache.lucene.index.NumericDocValues;
@@ -94,11 +97,19 @@ final class PerThreadIDVersionAndSeqNoLookup {
9497
this.loadedTimestampRange = loadTimestampRange;
9598
// Also check for the existence of the timestamp field, because sometimes a segment can only contain tombstone documents,
9699
// which don't have any mapped fields (also not the timestamp field) and just some meta fields like _id, _seq_no etc.
97-
if (loadTimestampRange && reader.getFieldInfos().fieldInfo(DataStream.TIMESTAMP_FIELD_NAME) != null) {
98-
PointValues tsPointValues = reader.getPointValues(DataStream.TIMESTAMP_FIELD_NAME);
99-
assert tsPointValues != null : "no timestamp field for reader:" + reader + " and parent:" + reader.getContext().parent.reader();
100-
minTimestamp = LongPoint.decodeDimension(tsPointValues.getMinPackedValue(), 0);
101-
maxTimestamp = LongPoint.decodeDimension(tsPointValues.getMaxPackedValue(), 0);
100+
FieldInfo info = reader.getFieldInfos().fieldInfo(DataStream.TIMESTAMP_FIELD_NAME);
101+
if (loadTimestampRange && info != null) {
102+
if (info.docValuesSkipIndexType() == DocValuesSkipIndexType.RANGE) {
103+
DocValuesSkipper skipper = reader.getDocValuesSkipper(DataStream.TIMESTAMP_FIELD_NAME);
104+
minTimestamp = skipper.minValue();
105+
maxTimestamp = skipper.maxValue();
106+
} else {
107+
PointValues tsPointValues = reader.getPointValues(DataStream.TIMESTAMP_FIELD_NAME);
108+
assert tsPointValues != null
109+
: "no timestamp field for reader:" + reader + " and parent:" + reader.getContext().parent.reader();
110+
minTimestamp = LongPoint.decodeDimension(tsPointValues.getMinPackedValue(), 0);
111+
maxTimestamp = LongPoint.decodeDimension(tsPointValues.getMaxPackedValue(), 0);
112+
}
102113
} else {
103114
minTimestamp = 0;
104115
maxTimestamp = Long.MAX_VALUE;

0 commit comments

Comments
 (0)