Skip to content

Revert "Use IndexOrDocValuesQuery in NumberFieldType#termQuery implementations (#128293)" #129206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions docs/changelog/128293.yaml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ public boolean isSearchable() {
public Query termQuery(Object value, SearchExecutionContext context) {
failIfNotIndexedNorDocValuesFallback(context);
long scaledValue = Math.round(scale(value));
return NumberFieldMapper.NumberType.LONG.termQuery(name(), scaledValue, isIndexed(), hasDocValues());
return NumberFieldMapper.NumberType.LONG.termQuery(name(), scaledValue, isIndexed());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.MapperBuilderContext;
import org.elasticsearch.index.mapper.NumberFieldMapper;
import org.elasticsearch.lucene.document.NumericField;

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

MappedFieldType ft2 = new ScaledFloatFieldMapper.ScaledFloatFieldType("scaled_float", 0.1 + randomDouble() * 100, false);
ElasticsearchException e2 = expectThrows(ElasticsearchException.class, () -> ft2.termQuery("42", MOCK_CONTEXT_DISALLOW_EXPENSIVE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import org.elasticsearch.index.fielddata.plain.SortedNumericIndexFieldData;
import org.elasticsearch.index.mapper.TimeSeriesParams.MetricType;
import org.elasticsearch.index.query.SearchExecutionContext;
import org.elasticsearch.lucene.document.NumericField;
import org.elasticsearch.lucene.search.XIndexSortSortedNumericDocValuesRangeQuery;
import org.elasticsearch.script.DoubleFieldScript;
import org.elasticsearch.script.LongFieldScript;
Expand Down Expand Up @@ -352,19 +351,13 @@ public Float parse(XContentParser parser, boolean coerce) throws IOException {
}

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

if (isIndexed) {
if (hasDocValues) {
return new IndexOrDocValuesQuery(
HalfFloatPoint.newExactQuery(field, v),
SortedNumericDocValuesField.newSlowExactQuery(field, HalfFloatPoint.halfFloatToSortableShort(v))
);
}
return HalfFloatPoint.newExactQuery(field, v);
} else {
return SortedNumericDocValuesField.newSlowExactQuery(field, HalfFloatPoint.halfFloatToSortableShort(v));
Expand Down Expand Up @@ -548,15 +541,13 @@ public Float parse(XContentParser parser, boolean coerce) throws IOException {
}

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

if (isIndexed && hasDocValues) {
return FloatField.newExactQuery(field, v);
} else if (isIndexed) {
if (isIndexed) {
return FloatPoint.newExactQuery(field, v);
} else {
return SortedNumericDocValuesField.newSlowExactQuery(field, NumericUtils.floatToSortableInt(v));
Expand Down Expand Up @@ -723,15 +714,13 @@ public FieldValues<Number> compile(String fieldName, Script script, ScriptCompil
}

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

if (isIndexed && hasDocValues) {
return DoubleField.newExactQuery(field, v);
} else if (isIndexed) {
if (isIndexed) {
return DoublePoint.newExactQuery(field, v);
} else {
return SortedNumericDocValuesField.newSlowExactQuery(field, NumericUtils.doubleToSortableLong(v));
Expand Down Expand Up @@ -885,12 +874,12 @@ public Byte parse(XContentParser parser, boolean coerce) throws IOException {
}

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

return INTEGER.termQuery(field, value, isIndexed, hasDocValues);
return INTEGER.termQuery(field, value, isIndexed);
}

@Override
Expand Down Expand Up @@ -1009,11 +998,11 @@ public Short parse(XContentParser parser, boolean coerce) throws IOException {
}

@Override
public Query termQuery(String field, Object value, boolean isIndexed, boolean hasDocValues) {
public Query termQuery(String field, Object value, boolean isIndexed) {
if (isOutOfRange(value)) {
return Queries.newMatchNoDocsQuery("Value [" + value + "] is out of range");
}
return INTEGER.termQuery(field, value, isIndexed, hasDocValues);
return INTEGER.termQuery(field, value, isIndexed);
}

@Override
Expand Down Expand Up @@ -1135,7 +1124,7 @@ public Integer parse(XContentParser parser, boolean coerce) throws IOException {
}

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

if (isIndexed && hasDocValues) {
return NumericField.newExactIntQuery(field, v);
} else if (isIndexed) {
if (isIndexed) {
return IntPoint.newExactQuery(field, v);
} else {
return SortedNumericDocValuesField.newSlowExactQuery(field, v);
Expand Down Expand Up @@ -1321,7 +1308,7 @@ public FieldValues<Number> compile(String fieldName, Script script, ScriptCompil
}

@Override
public Query termQuery(String field, Object value, boolean isIndexed, boolean hasDocValues) {
public Query termQuery(String field, Object value, boolean isIndexed) {
if (hasDecimalPart(value)) {
return Queries.newMatchNoDocsQuery("Value [" + value + "] has a decimal part");
}
Expand All @@ -1330,9 +1317,7 @@ public Query termQuery(String field, Object value, boolean isIndexed, boolean ha
}

long v = parse(value, true);
if (isIndexed && hasDocValues) {
return NumericField.newExactLongQuery(field, v);
} else if (isIndexed) {
if (isIndexed) {
return LongPoint.newExactQuery(field, v);
} else {
return SortedNumericDocValuesField.newSlowExactQuery(field, v);
Expand Down Expand Up @@ -1515,7 +1500,7 @@ public final TypeParser parser() {
return parser;
}

public abstract Query termQuery(String field, Object value, boolean isIndexed, boolean hasDocValues);
public abstract Query termQuery(String field, Object value, boolean isIndexed);

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

Expand Down Expand Up @@ -1906,11 +1891,11 @@ public NumberFieldType(
}

public NumberFieldType(String name, NumberType type) {
this(name, type, true, true);
this(name, type, true);
}

public NumberFieldType(String name, NumberType type, boolean isIndexed, boolean hasDocValues) {
this(name, type, isIndexed, false, hasDocValues, true, null, Collections.emptyMap(), null, false, null, null, false);
public NumberFieldType(String name, NumberType type, boolean isIndexed) {
this(name, type, isIndexed, false, true, true, null, Collections.emptyMap(), null, false, null, null, false);
}

@Override
Expand Down Expand Up @@ -1949,7 +1934,7 @@ public boolean isSearchable() {
@Override
public Query termQuery(Object value, SearchExecutionContext context) {
failIfNotIndexedNorDocValuesFallback(context);
return type.termQuery(name(), value, isIndexed(), hasDocValues());
return type.termQuery(name(), value, isIndexed());
}

@Override
Expand Down
Loading
Loading