Skip to content

Commit 9a49075

Browse files
authored
Simplify range query methods for range types. (#56976)
For me this is easier to follow. It also avoids parsing the query bounds twice.
1 parent 2ed9144 commit 9a49075

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public List<RangeFieldMapper.Range> decodeRanges(BytesRef bytes) {
214214
}
215215

216216
@Override
217-
public Double doubleValue (Object endpointValue) {
217+
public Double doubleValue(Object endpointValue) {
218218
return LONG.doubleValue(endpointValue);
219219
}
220220

@@ -233,16 +233,15 @@ public Query rangeQuery(String field, boolean hasDocValues, Object lowerTerm, Ob
233233
DateMathParser dateMathParser = (parser == null) ?
234234
DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER.toDateMathParser() : parser;
235235
boolean roundUp = includeLower == false; // using "gt" should round lower bound up
236-
Long low = lowerTerm == null ? Long.MIN_VALUE :
236+
Long low = lowerTerm == null ? minValue() :
237237
dateMathParser.parse(lowerTerm instanceof BytesRef ? ((BytesRef) lowerTerm).utf8ToString() : lowerTerm.toString(),
238238
context::nowInMillis, roundUp, zone).toEpochMilli();
239239
roundUp = includeUpper; // using "lte" should round upper bound up
240-
Long high = upperTerm == null ? Long.MAX_VALUE :
240+
Long high = upperTerm == null ? maxValue() :
241241
dateMathParser.parse(upperTerm instanceof BytesRef ? ((BytesRef) upperTerm).utf8ToString() : upperTerm.toString(),
242242
context::nowInMillis, roundUp, zone).toEpochMilli();
243243

244-
return super.rangeQuery(field, hasDocValues, low, high, includeLower, includeUpper, relation, zone,
245-
dateMathParser, context);
244+
return createRangeQuery(field, hasDocValues, low, high, includeLower, includeUpper, relation);
246245
}
247246
@Override
248247
public Query withinQuery(String field, Object from, Object to, boolean includeLower, boolean includeUpper) {
@@ -622,11 +621,17 @@ public Object parseTo(RangeFieldMapper.RangeFieldType fieldType, XContentParser
622621
public Object parse(Object value, boolean coerce) {
623622
return numberType.parse(value, coerce);
624623
}
624+
625625
public Query rangeQuery(String field, boolean hasDocValues, Object from, Object to, boolean includeFrom, boolean includeTo,
626626
ShapeRelation relation, @Nullable ZoneId timeZone, @Nullable DateMathParser dateMathParser,
627627
QueryShardContext context) {
628628
Object lower = from == null ? minValue() : parse(from, false);
629629
Object upper = to == null ? maxValue() : parse(to, false);
630+
return createRangeQuery(field, hasDocValues, lower, upper, includeFrom, includeTo, relation);
631+
}
632+
633+
protected final Query createRangeQuery(String field, boolean hasDocValues, Object lower, Object upper,
634+
boolean includeFrom, boolean includeTo, ShapeRelation relation) {
630635
Query indexQuery;
631636
if (relation == ShapeRelation.WITHIN) {
632637
indexQuery = withinQuery(field, lower, upper, includeFrom, includeTo);

0 commit comments

Comments
 (0)