Skip to content

Commit f02a3c4

Browse files
authored
Revert "Use IndexOrDocValuesQuery in NumberFieldType#termQuery implementations (#128293)" (#129206)
This reverts commit de7c91c.
1 parent 0702e42 commit f02a3c4

File tree

10 files changed

+81
-222
lines changed

10 files changed

+81
-222
lines changed

docs/changelog/128293.yaml

Lines changed: 0 additions & 5 deletions
This file was deleted.

modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/extras/ScaledFloatFieldMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ public boolean isSearchable() {
323323
public Query termQuery(Object value, SearchExecutionContext context) {
324324
failIfNotIndexedNorDocValuesFallback(context);
325325
long scaledValue = Math.round(scale(value));
326-
return NumberFieldMapper.NumberType.LONG.termQuery(name(), scaledValue, isIndexed(), hasDocValues());
326+
return NumberFieldMapper.NumberType.LONG.termQuery(name(), scaledValue, isIndexed());
327327
}
328328

329329
@Override

modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/extras/ScaledFloatFieldTypeTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import org.elasticsearch.index.mapper.MappedFieldType;
3131
import org.elasticsearch.index.mapper.MapperBuilderContext;
3232
import org.elasticsearch.index.mapper.NumberFieldMapper;
33-
import org.elasticsearch.lucene.document.NumericField;
3433

3534
import java.io.IOException;
3635
import java.util.Arrays;
@@ -48,7 +47,7 @@ public void testTermQuery() {
4847
);
4948
double value = (randomDouble() * 2 - 1) * 10000;
5049
long scaledValue = Math.round(value * ft.getScalingFactor());
51-
assertEquals(NumericField.newExactLongQuery("scaled_float", scaledValue), ft.termQuery(value, MOCK_CONTEXT));
50+
assertEquals(LongPoint.newExactQuery("scaled_float", scaledValue), ft.termQuery(value, MOCK_CONTEXT));
5251

5352
MappedFieldType ft2 = new ScaledFloatFieldMapper.ScaledFloatFieldType("scaled_float", 0.1 + randomDouble() * 100, false);
5453
ElasticsearchException e2 = expectThrows(ElasticsearchException.class, () -> ft2.termQuery("42", MOCK_CONTEXT_DISALLOW_EXPENSIVE));

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

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import org.elasticsearch.index.fielddata.plain.SortedNumericIndexFieldData;
4747
import org.elasticsearch.index.mapper.TimeSeriesParams.MetricType;
4848
import org.elasticsearch.index.query.SearchExecutionContext;
49-
import org.elasticsearch.lucene.document.NumericField;
5049
import org.elasticsearch.lucene.search.XIndexSortSortedNumericDocValuesRangeQuery;
5150
import org.elasticsearch.script.DoubleFieldScript;
5251
import org.elasticsearch.script.LongFieldScript;
@@ -352,19 +351,13 @@ public Float parse(XContentParser parser, boolean coerce) throws IOException {
352351
}
353352

354353
@Override
355-
public Query termQuery(String field, Object value, boolean isIndexed, boolean hasDocValues) {
354+
public Query termQuery(String field, Object value, boolean isIndexed) {
356355
float v = parseToFloat(value);
357356
if (Float.isFinite(HalfFloatPoint.sortableShortToHalfFloat(HalfFloatPoint.halfFloatToSortableShort(v))) == false) {
358357
return Queries.newMatchNoDocsQuery("Value [" + value + "] is out of range");
359358
}
360359

361360
if (isIndexed) {
362-
if (hasDocValues) {
363-
return new IndexOrDocValuesQuery(
364-
HalfFloatPoint.newExactQuery(field, v),
365-
SortedNumericDocValuesField.newSlowExactQuery(field, HalfFloatPoint.halfFloatToSortableShort(v))
366-
);
367-
}
368361
return HalfFloatPoint.newExactQuery(field, v);
369362
} else {
370363
return SortedNumericDocValuesField.newSlowExactQuery(field, HalfFloatPoint.halfFloatToSortableShort(v));
@@ -548,15 +541,13 @@ public Float parse(XContentParser parser, boolean coerce) throws IOException {
548541
}
549542

550543
@Override
551-
public Query termQuery(String field, Object value, boolean isIndexed, boolean hasDocValues) {
544+
public Query termQuery(String field, Object value, boolean isIndexed) {
552545
float v = parseToFloat(value);
553546
if (Float.isFinite(v) == false) {
554547
return new MatchNoDocsQuery("Value [" + value + "] is out of range");
555548
}
556549

557-
if (isIndexed && hasDocValues) {
558-
return FloatField.newExactQuery(field, v);
559-
} else if (isIndexed) {
550+
if (isIndexed) {
560551
return FloatPoint.newExactQuery(field, v);
561552
} else {
562553
return SortedNumericDocValuesField.newSlowExactQuery(field, NumericUtils.floatToSortableInt(v));
@@ -723,15 +714,13 @@ public FieldValues<Number> compile(String fieldName, Script script, ScriptCompil
723714
}
724715

725716
@Override
726-
public Query termQuery(String field, Object value, boolean isIndexed, boolean hasDocValues) {
717+
public Query termQuery(String field, Object value, boolean isIndexed) {
727718
double v = objectToDouble(value);
728719
if (Double.isFinite(v) == false) {
729720
return Queries.newMatchNoDocsQuery("Value [" + value + "] has a decimal part");
730721
}
731722

732-
if (isIndexed && hasDocValues) {
733-
return DoubleField.newExactQuery(field, v);
734-
} else if (isIndexed) {
723+
if (isIndexed) {
735724
return DoublePoint.newExactQuery(field, v);
736725
} else {
737726
return SortedNumericDocValuesField.newSlowExactQuery(field, NumericUtils.doubleToSortableLong(v));
@@ -885,12 +874,12 @@ public Byte parse(XContentParser parser, boolean coerce) throws IOException {
885874
}
886875

887876
@Override
888-
public Query termQuery(String field, Object value, boolean isIndexed, boolean hasDocValues) {
877+
public Query termQuery(String field, Object value, boolean isIndexed) {
889878
if (isOutOfRange(value)) {
890879
return new MatchNoDocsQuery("Value [" + value + "] is out of range");
891880
}
892881

893-
return INTEGER.termQuery(field, value, isIndexed, hasDocValues);
882+
return INTEGER.termQuery(field, value, isIndexed);
894883
}
895884

896885
@Override
@@ -1009,11 +998,11 @@ public Short parse(XContentParser parser, boolean coerce) throws IOException {
1009998
}
1010999

10111000
@Override
1012-
public Query termQuery(String field, Object value, boolean isIndexed, boolean hasDocValues) {
1001+
public Query termQuery(String field, Object value, boolean isIndexed) {
10131002
if (isOutOfRange(value)) {
10141003
return Queries.newMatchNoDocsQuery("Value [" + value + "] is out of range");
10151004
}
1016-
return INTEGER.termQuery(field, value, isIndexed, hasDocValues);
1005+
return INTEGER.termQuery(field, value, isIndexed);
10171006
}
10181007

10191008
@Override
@@ -1135,7 +1124,7 @@ public Integer parse(XContentParser parser, boolean coerce) throws IOException {
11351124
}
11361125

11371126
@Override
1138-
public Query termQuery(String field, Object value, boolean isIndexed, boolean hasDocValues) {
1127+
public Query termQuery(String field, Object value, boolean isIndexed) {
11391128
if (hasDecimalPart(value)) {
11401129
return Queries.newMatchNoDocsQuery("Value [" + value + "] has a decimal part");
11411130
}
@@ -1146,9 +1135,7 @@ public Query termQuery(String field, Object value, boolean isIndexed, boolean ha
11461135
}
11471136
int v = parse(value, true);
11481137

1149-
if (isIndexed && hasDocValues) {
1150-
return NumericField.newExactIntQuery(field, v);
1151-
} else if (isIndexed) {
1138+
if (isIndexed) {
11521139
return IntPoint.newExactQuery(field, v);
11531140
} else {
11541141
return SortedNumericDocValuesField.newSlowExactQuery(field, v);
@@ -1321,7 +1308,7 @@ public FieldValues<Number> compile(String fieldName, Script script, ScriptCompil
13211308
}
13221309

13231310
@Override
1324-
public Query termQuery(String field, Object value, boolean isIndexed, boolean hasDocValues) {
1311+
public Query termQuery(String field, Object value, boolean isIndexed) {
13251312
if (hasDecimalPart(value)) {
13261313
return Queries.newMatchNoDocsQuery("Value [" + value + "] has a decimal part");
13271314
}
@@ -1330,9 +1317,7 @@ public Query termQuery(String field, Object value, boolean isIndexed, boolean ha
13301317
}
13311318

13321319
long v = parse(value, true);
1333-
if (isIndexed && hasDocValues) {
1334-
return NumericField.newExactLongQuery(field, v);
1335-
} else if (isIndexed) {
1320+
if (isIndexed) {
13361321
return LongPoint.newExactQuery(field, v);
13371322
} else {
13381323
return SortedNumericDocValuesField.newSlowExactQuery(field, v);
@@ -1515,7 +1500,7 @@ public final TypeParser parser() {
15151500
return parser;
15161501
}
15171502

1518-
public abstract Query termQuery(String field, Object value, boolean isIndexed, boolean hasDocValues);
1503+
public abstract Query termQuery(String field, Object value, boolean isIndexed);
15191504

15201505
public abstract Query termsQuery(String field, Collection<?> values);
15211506

@@ -1906,11 +1891,11 @@ public NumberFieldType(
19061891
}
19071892

19081893
public NumberFieldType(String name, NumberType type) {
1909-
this(name, type, true, true);
1894+
this(name, type, true);
19101895
}
19111896

1912-
public NumberFieldType(String name, NumberType type, boolean isIndexed, boolean hasDocValues) {
1913-
this(name, type, isIndexed, false, hasDocValues, true, null, Collections.emptyMap(), null, false, null, null, false);
1897+
public NumberFieldType(String name, NumberType type, boolean isIndexed) {
1898+
this(name, type, isIndexed, false, true, true, null, Collections.emptyMap(), null, false, null, null, false);
19141899
}
19151900

19161901
@Override
@@ -1949,7 +1934,7 @@ public boolean isSearchable() {
19491934
@Override
19501935
public Query termQuery(Object value, SearchExecutionContext context) {
19511936
failIfNotIndexedNorDocValuesFallback(context);
1952-
return type.termQuery(name(), value, isIndexed(), hasDocValues());
1937+
return type.termQuery(name(), value, isIndexed());
19531938
}
19541939

19551940
@Override

0 commit comments

Comments
 (0)