diff --git a/server/src/main/java/org/opensearch/index/document/SortedUnsignedLongDocValuesSetQuery.java b/server/src/main/java/org/opensearch/index/document/SortedUnsignedLongDocValuesSetQuery.java index 2372adbdacf52..669dbb1e1bfc7 100644 --- a/server/src/main/java/org/opensearch/index/document/SortedUnsignedLongDocValuesSetQuery.java +++ b/server/src/main/java/org/opensearch/index/document/SortedUnsignedLongDocValuesSetQuery.java @@ -158,4 +158,19 @@ SortedNumericDocValues getValues(LeafReader reader, String field) throws IOExcep } }; } + + public static Query newSlowExactQuery(String field, BigInteger value) { + return new SortedUnsignedLongDocValuesRangeQuery(field, value, value) { + @Override + SortedNumericDocValues getValues(LeafReader reader, String field) throws IOException { + FieldInfo info = reader.getFieldInfos().fieldInfo(field); + if (info == null) { + // Queries have some optimizations when one sub scorer returns null rather + // than a scorer that does not match any documents + return null; + } + return DocValues.getSortedNumeric(reader, field); + } + }; + } } 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 003167d86f5b6..524d2b0e0dd38 100644 --- a/server/src/main/java/org/opensearch/index/mapper/NumberFieldMapper.java +++ b/server/src/main/java/org/opensearch/index/mapper/NumberFieldMapper.java @@ -1002,11 +1002,11 @@ public Query termQuery(String field, Object value, boolean hasDocValues, boolean BigInteger v = parse(value, true); if (isSearchable && hasDocValues) { Query query = BigIntegerPoint.newExactQuery(field, v); - Query dvQuery = SortedUnsignedLongDocValuesRangeQuery.newSlowRangeQuery(field, v, v); + Query dvQuery = SortedUnsignedLongDocValuesSetQuery.newSlowExactQuery(field, v); return new IndexOrDocValuesQuery(query, dvQuery); } if (hasDocValues) { - return SortedUnsignedLongDocValuesRangeQuery.newSlowRangeQuery(field, v, v); + return SortedUnsignedLongDocValuesSetQuery.newSlowExactQuery(field, v); } return BigIntegerPoint.newExactQuery(field, v); }