Skip to content

Commit bc89576

Browse files
committed
Use doc values skipper for DateFieldType#isFieldWithinQuery
1 parent c8607b2 commit bc89576

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

server/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.apache.lucene.document.LongPoint;
1717
import org.apache.lucene.document.SortedNumericDocValuesField;
1818
import org.apache.lucene.document.StoredField;
19+
import org.apache.lucene.index.DocValuesSkipper;
1920
import org.apache.lucene.index.IndexReader;
2021
import org.apache.lucene.index.LeafReaderContext;
2122
import org.apache.lucene.index.PointValues;
@@ -69,6 +70,7 @@
6970
import java.time.ZoneOffset;
7071
import java.time.ZonedDateTime;
7172
import java.util.Collections;
73+
import java.util.List;
7274
import java.util.Locale;
7375
import java.util.Map;
7476
import java.util.Objects;
@@ -827,8 +829,24 @@ public Relation isFieldWithinQuery(
827829
QueryRewriteContext context
828830
) throws IOException {
829831
if (isIndexed() == false && pointsMetadataAvailable == false && hasDocValues()) {
830-
// we don't have a quick way to run this check on doc values, so fall back to default assuming we are within bounds
831-
return Relation.INTERSECTS;
832+
if (hasDocValuesSkipper() == false) {
833+
// we don't have a quick way to run this check on doc values, so fall back to default assuming we are within bounds
834+
return Relation.INTERSECTS;
835+
}
836+
long minValue = Long.MAX_VALUE;
837+
long maxValue = Long.MIN_VALUE;
838+
List<LeafReaderContext> leaves = reader.leaves();
839+
if (leaves.size() == 0) {
840+
// no data, so nothing matches
841+
return Relation.DISJOINT;
842+
}
843+
for (LeafReaderContext ctx : leaves) {
844+
DocValuesSkipper skipper = ctx.reader().getDocValuesSkipper(name());
845+
assert skipper != null : "no skipper for field:" + name() + " and reader:" + reader;
846+
minValue = Long.min(minValue, skipper.minValue());
847+
maxValue = Long.max(maxValue, skipper.maxValue());
848+
}
849+
return isFieldWithinQuery(minValue, maxValue, from, to, includeLower, includeUpper, timeZone, dateParser, context);
832850
}
833851
byte[] minPackedValue = PointValues.getMinPackedValue(reader, name());
834852
if (minPackedValue == null) {

0 commit comments

Comments
 (0)