@@ -434,7 +434,7 @@ public static FieldSortBuilder getPrimaryFieldSortOrNull(SearchSourceBuilder sou
434434 * {@link SortField}. This is needed for {@link SortField} that converts values from one type to another using
435435 * {@link FieldSortBuilder#setNumericType(String)} )} (e.g.: long to double).
436436 */
437- private static Function <byte [], Comparable > numericPointConverter (SortField sortField , NumberFieldType numberFieldType ) {
437+ private static Function <byte [], Comparable <?> > numericPointConverter (SortField sortField , NumberFieldType numberFieldType ) {
438438 switch (IndexSortConfig .getSortFieldType (sortField )) {
439439 case LONG :
440440 return v -> numberFieldType .parsePoint (v ).longValue ();
@@ -457,7 +457,7 @@ private static Function<byte[], Comparable> numericPointConverter(SortField sort
457457 * Return a {@link Function} that converts a serialized date point into a {@link Long} according to the provided
458458 * {@link NumericType}.
459459 */
460- private static Function <byte [], Comparable > datePointConverter (DateFieldType dateFieldType , String numericTypeStr ) {
460+ private static Function <byte [], Comparable <?> > datePointConverter (DateFieldType dateFieldType , String numericTypeStr ) {
461461 if (numericTypeStr != null ) {
462462 NumericType numericType = resolveNumericType (numericTypeStr );
463463 if (dateFieldType .resolution () == MILLISECONDS && numericType == NumericType .DATE_NANOSECONDS ) {
@@ -491,7 +491,7 @@ public static MinAndMax<?> getMinMaxOrNull(QueryShardContext context, FieldSortB
491491 case INT :
492492 case DOUBLE :
493493 case FLOAT :
494- final Function <byte [], Comparable > converter ;
494+ final Function <byte [], Comparable <?> > converter ;
495495 if (fieldType instanceof NumberFieldType ) {
496496 converter = numericPointConverter (sortField , (NumberFieldType ) fieldType );
497497 } else if (fieldType instanceof DateFieldType ) {
@@ -502,9 +502,7 @@ public static MinAndMax<?> getMinMaxOrNull(QueryShardContext context, FieldSortB
502502 if (PointValues .size (reader , fieldName ) == 0 ) {
503503 return null ;
504504 }
505- final Comparable min = converter .apply (PointValues .getMinPackedValue (reader , fieldName ));
506- final Comparable max = converter .apply (PointValues .getMaxPackedValue (reader , fieldName ));
507- return MinAndMax .newMinMax (min , max );
505+ return extractMinAndMax (reader , fieldName , converter );
508506
509507 case STRING :
510508 case STRING_VAL :
@@ -520,6 +518,14 @@ public static MinAndMax<?> getMinMaxOrNull(QueryShardContext context, FieldSortB
520518 return null ;
521519 }
522520
521+ @ SuppressWarnings ("unchecked" )
522+ private static <T extends Comparable <T >> MinAndMax <T > extractMinAndMax (IndexReader reader , String fieldName ,
523+ Function <byte [], Comparable <?>> converter ) throws IOException {
524+ final T min = (T )converter .apply (PointValues .getMinPackedValue (reader , fieldName ));
525+ final T max = (T )converter .apply (PointValues .getMaxPackedValue (reader , fieldName ));
526+ return MinAndMax .newMinMax (min , max );
527+ }
528+
523529 /**
524530 * Throws an exception if max children is not located at top level nested sort.
525531 */
@@ -601,12 +607,12 @@ public static FieldSortBuilder fromXContent(XContentParser parser, String fieldN
601607 private static final ObjectParser <FieldSortBuilder , Void > PARSER = new ObjectParser <>(NAME );
602608
603609 static {
604- PARSER .declareField (FieldSortBuilder ::missing , p -> p . objectText () , MISSING , ValueType .VALUE );
610+ PARSER .declareField (FieldSortBuilder ::missing , XContentParser :: objectText , MISSING , ValueType .VALUE );
605611 PARSER .declareString (FieldSortBuilder ::unmappedType , UNMAPPED_TYPE );
606612 PARSER .declareString ((b , v ) -> b .order (SortOrder .fromString (v )) , ORDER_FIELD );
607613 PARSER .declareString ((b , v ) -> b .sortMode (SortMode .fromString (v )), SORT_MODE );
608614 PARSER .declareObject (FieldSortBuilder ::setNestedSort , (p , c ) -> NestedSortBuilder .fromXContent (p ), NESTED_FIELD );
609- PARSER .declareString (( b , v ) -> b . setNumericType ( v ) , NUMERIC_TYPE );
615+ PARSER .declareString (FieldSortBuilder :: setNumericType , NUMERIC_TYPE );
610616 }
611617
612618 @ Override
0 commit comments