Skip to content

Commit 752881a

Browse files
committed
Break out isFieldWithinQuery optimization into separate PR
1 parent 3bee698 commit 752881a

File tree

2 files changed

+3
-61
lines changed

2 files changed

+3
-61
lines changed

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

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
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;
2019
import org.apache.lucene.index.IndexReader;
2120
import org.apache.lucene.index.LeafReaderContext;
2221
import org.apache.lucene.index.PointValues;
@@ -70,7 +69,6 @@
7069
import java.time.ZoneOffset;
7170
import java.time.ZonedDateTime;
7271
import java.util.Collections;
73-
import java.util.List;
7472
import java.util.Locale;
7573
import java.util.Map;
7674
import java.util.Objects;
@@ -829,24 +827,8 @@ public Relation isFieldWithinQuery(
829827
QueryRewriteContext context
830828
) throws IOException {
831829
if (isIndexed() == false && pointsMetadataAvailable == false && hasDocValues()) {
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);
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;
850832
}
851833
byte[] minPackedValue = PointValues.getMinPackedValue(reader, name());
852834
if (minPackedValue == null) {

server/src/test/java/org/elasticsearch/index/mapper/DateFieldTypeTests.java

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
*/
99
package org.elasticsearch.index.mapper;
1010

11-
import org.apache.lucene.document.Field;
1211
import org.apache.lucene.document.LongPoint;
1312
import org.apache.lucene.document.NumericDocValuesField;
1413
import org.apache.lucene.document.SortedNumericDocValuesField;
@@ -86,51 +85,12 @@ public void testIsFieldWithinQueryDateNanos() throws IOException {
8685
isFieldWithinRangeTestCase(ft);
8786
}
8887

89-
public void testIsFieldWithinQueryDateMillisDocValueSkipper() throws IOException {
90-
DateFieldType ft = new DateFieldType(
91-
"my_date",
92-
false,
93-
false,
94-
false,
95-
true,
96-
true,
97-
DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER,
98-
Resolution.MILLISECONDS,
99-
null,
100-
null,
101-
Collections.emptyMap()
102-
);
103-
isFieldWithinRangeTestCase(ft);
104-
}
105-
106-
public void testIsFieldWithinQueryDateNanosDocValueSkipper() throws IOException {
107-
DateFieldType ft = new DateFieldType(
108-
"my_date",
109-
false,
110-
false,
111-
false,
112-
true,
113-
true,
114-
DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER,
115-
Resolution.NANOSECONDS,
116-
null,
117-
null,
118-
Collections.emptyMap()
119-
);
120-
isFieldWithinRangeTestCase(ft);
121-
}
122-
12388
public void isFieldWithinRangeTestCase(DateFieldType ft) throws IOException {
12489

12590
Directory dir = newDirectory();
12691
IndexWriter w = new IndexWriter(dir, new IndexWriterConfig(null));
12792
LuceneDocument doc = new LuceneDocument();
128-
Field field;
129-
if (ft.hasDocValuesSkipper()) {
130-
field = SortedNumericDocValuesField.indexedField("my_date", ft.parse("2015-10-12"));
131-
} else {
132-
field = new LongPoint("my_date", ft.parse("2015-10-12"));
133-
}
93+
LongPoint field = new LongPoint("my_date", ft.parse("2015-10-12"));
13494
doc.add(field);
13595
w.addDocument(doc);
13696
field.setLongValue(ft.parse("2016-04-03"));

0 commit comments

Comments
 (0)