diff --git a/libs/common/src/main/java/org/opensearch/common/Numbers.java b/libs/common/src/main/java/org/opensearch/common/Numbers.java index d5a364a4a934e..fa4018089bdc4 100644 --- a/libs/common/src/main/java/org/opensearch/common/Numbers.java +++ b/libs/common/src/main/java/org/opensearch/common/Numbers.java @@ -41,6 +41,9 @@ * @opensearch.internal */ public final class Numbers { + + public static final BigInteger MAX_SIGNED_LONG = BigInteger.valueOf(Long.MAX_VALUE); + public static final BigInteger MAX_UNSIGNED_LONG_VALUE = BigInteger.ONE.shiftLeft(64).subtract(BigInteger.ONE); public static final BigInteger MIN_UNSIGNED_LONG_VALUE = BigInteger.ZERO; diff --git a/server/src/main/java/org/opensearch/index/fielddata/fieldcomparator/UnsignedLongValuesComparatorSource.java b/server/src/main/java/org/opensearch/index/fielddata/fieldcomparator/UnsignedLongValuesComparatorSource.java index 9db5817450cd0..3e8e513e80747 100644 --- a/server/src/main/java/org/opensearch/index/fielddata/fieldcomparator/UnsignedLongValuesComparatorSource.java +++ b/server/src/main/java/org/opensearch/index/fielddata/fieldcomparator/UnsignedLongValuesComparatorSource.java @@ -78,7 +78,7 @@ private NumericDocValues getNumericDocValues(LeafReaderContext context, BigInteg public Object missingObject(Object missingValue, boolean reversed) { if (sortMissingFirst(missingValue) || sortMissingLast(missingValue)) { final boolean min = sortMissingFirst(missingValue) ^ reversed; - return min ? Numbers.MIN_UNSIGNED_LONG_VALUE : Numbers.MAX_UNSIGNED_LONG_VALUE; + return min ? Numbers.MIN_UNSIGNED_LONG_VALUE : Numbers.MAX_SIGNED_LONG; } else { if (missingValue instanceof Number) { return Numbers.toUnsignedLongExact((Number) missingValue);