From e087885c392b8ad7e92703e6a9c9698d94116dfc Mon Sep 17 00:00:00 2001 From: Harsha Vamsi Kalluri Date: Fri, 8 Dec 2023 13:28:02 -0800 Subject: [PATCH] Use slowExactQuery from Unsigned Set Query Signed-off-by: Harsha Vamsi Kalluri --- .../SortedUnsignedLongDocValuesSetQuery.java | 15 +++++++++++++++ .../index/mapper/NumberFieldMapper.java | 4 ++-- 2 files changed, 17 insertions(+), 2 deletions(-) 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); }