diff --git a/server/src/main/java/org/opensearch/index/mapper/NumberFieldMapper.java b/server/src/main/java/org/opensearch/index/mapper/NumberFieldMapper.java index 204e7bc4c16ab..91ca2de3fe639 100644 --- a/server/src/main/java/org/opensearch/index/mapper/NumberFieldMapper.java +++ b/server/src/main/java/org/opensearch/index/mapper/NumberFieldMapper.java @@ -201,9 +201,16 @@ public Float parse(XContentParser parser, boolean coerce) throws IOException { } @Override - public Query termQuery(String field, Object value) { + public Query termQuery(String field, Object value, Boolean hasDocValues) { float v = parse(value, false); - return HalfFloatPoint.newExactQuery(field, v); + Query query = HalfFloatPoint.newExactQuery(field, v); + if(hasDocValues){ + Query dvQuery = SortedNumericDocValuesField.newSlowExactQuery( + field, HalfFloatPoint.halfFloatToSortableShort(v) + ); + query = new IndexOrDocValuesQuery(query, dvQuery); + } + return query; } @Override @@ -309,9 +316,15 @@ public Float parse(XContentParser parser, boolean coerce) throws IOException { } @Override - public Query termQuery(String field, Object value) { + public Query termQuery(String field, Object value, Boolean hasDocValues) { float v = parse(value, false); - return FloatPoint.newExactQuery(field, v); + Query query = FloatPoint.newExactQuery(field, v); + if(hasDocValues){ + Query dvQuery = SortedNumericDocValuesField.newSlowExactQuery(field, + NumericUtils.floatToSortableInt(v)); + query = new IndexOrDocValuesQuery(query, dvQuery); + } + return query; } @Override @@ -406,9 +419,15 @@ public Double parse(XContentParser parser, boolean coerce) throws IOException { } @Override - public Query termQuery(String field, Object value) { + public Query termQuery(String field, Object value, Boolean hasDocValues) { double v = parse(value, false); - return DoublePoint.newExactQuery(field, v); + Query query = DoublePoint.newExactQuery(field, v); + if(hasDocValues){ + Query dvQuery = SortedNumericDocValuesField.newSlowExactQuery(field, + NumericUtils.doubleToSortableLong(v)); + query = new IndexOrDocValuesQuery(query, dvQuery); + } + return query; } @Override @@ -504,8 +523,8 @@ public Short parse(XContentParser parser, boolean coerce) throws IOException { } @Override - public Query termQuery(String field, Object value) { - return INTEGER.termQuery(field, value); + public Query termQuery(String field, Object value, Boolean hasDocValues) { + return INTEGER.termQuery(field, value, hasDocValues); } @Override @@ -571,8 +590,8 @@ public Short parse(XContentParser parser, boolean coerce) throws IOException { } @Override - public Query termQuery(String field, Object value) { - return INTEGER.termQuery(field, value); + public Query termQuery(String field, Object value, Boolean hasDocValues) { + return INTEGER.termQuery(field, value, hasDocValues); } @Override @@ -638,12 +657,17 @@ public Integer parse(XContentParser parser, boolean coerce) throws IOException { } @Override - public Query termQuery(String field, Object value) { + public Query termQuery(String field, Object value, Boolean hasDocValues) { if (hasDecimalPart(value)) { return Queries.newMatchNoDocsQuery("Value [" + value + "] has a decimal part"); } int v = parse(value, true); - return IntPoint.newExactQuery(field, v); + Query query = IntPoint.newExactQuery(field, v); + if(hasDocValues){ + Query dvQuery = SortedNumericDocValuesField.newSlowExactQuery(field, v); + query = new IndexOrDocValuesQuery(query, dvQuery); + } + return query; } @Override @@ -752,12 +776,17 @@ public Long parse(XContentParser parser, boolean coerce) throws IOException { } @Override - public Query termQuery(String field, Object value) { + public Query termQuery(String field, Object value, Boolean hasDocValues) { if (hasDecimalPart(value)) { return Queries.newMatchNoDocsQuery("Value [" + value + "] has a decimal part"); } long v = parse(value, true); - return LongPoint.newExactQuery(field, v); + Query query = LongPoint.newExactQuery(field, v); + if(hasDocValues){ + Query dvQuery = SortedNumericDocValuesField.newSlowExactQuery(field, v); + query = new IndexOrDocValuesQuery(query, dvQuery); + } + return query; } @Override @@ -841,12 +870,12 @@ public BigInteger parse(XContentParser parser, boolean coerce) throws IOExceptio } @Override - public Query termQuery(String field, Object value) { + public Query termQuery(String field, Object value, Boolean hasDocValues) { if (hasDecimalPart(value)) { return Queries.newMatchNoDocsQuery("Value [" + value + "] has a decimal part"); } BigInteger v = parse(value, true); - return BigIntegerPoint.newExactQuery(field, v); + return UNSIGNED_LONG.rangeQuery(field, v, v, true, true, hasDocValues, null); } @Override @@ -941,7 +970,7 @@ public final TypeParser parser() { return parser; } - public abstract Query termQuery(String field, Object value); + public abstract Query termQuery(String field, Object value, Boolean hasDocValues); public abstract Query termsQuery(String field, List values); @@ -1226,8 +1255,8 @@ public NumericType numericType() { @Override public Query termQuery(Object value, QueryShardContext context) { - failIfNotIndexed(); - Query query = type.termQuery(name(), value); + failIfNotIndexedAndNoDocValues(); + Query query = type.termQuery(name(), value, hasDocValues()); if (boost() != 1f) { query = new BoostQuery(query, boost()); } @@ -1236,7 +1265,7 @@ public Query termQuery(Object value, QueryShardContext context) { @Override public Query termsQuery(List values, QueryShardContext context) { - failIfNotIndexed(); + failIfNotIndexedAndNoDocValues(); Query query = type.termsQuery(name(), values); if (boost() != 1f) { query = new BoostQuery(query, boost()); @@ -1246,7 +1275,7 @@ public Query termsQuery(List values, QueryShardContext context) { @Override public Query rangeQuery(Object lowerTerm, Object upperTerm, boolean includeLower, boolean includeUpper, QueryShardContext context) { - failIfNotIndexed(); + failIfNotIndexedAndNoDocValues(); Query query = type.rangeQuery(name(), lowerTerm, upperTerm, includeLower, includeUpper, hasDocValues(), context); if (boost() != 1f) { query = new BoostQuery(query, boost());