protected <N extends Number> NumericRangeQuery<?> numericRange(
     Class<N> clazz,
     String field,
     @Nullable N min,
     @Nullable N max,
     boolean minInc,
     boolean maxInc) {
   if (clazz.equals(Integer.class)) {
     return NumericRangeQuery.newIntRange(field, (Integer) min, (Integer) max, minInc, maxInc);
   } else if (clazz.equals(Double.class)) {
     return NumericRangeQuery.newDoubleRange(field, (Double) min, (Double) max, minInc, minInc);
   } else if (clazz.equals(Float.class)) {
     return NumericRangeQuery.newFloatRange(field, (Float) min, (Float) max, minInc, minInc);
   } else if (clazz.equals(Long.class)) {
     return NumericRangeQuery.newLongRange(field, (Long) min, (Long) max, minInc, minInc);
   } else if (clazz.equals(Byte.class) || clazz.equals(Short.class)) {
     return NumericRangeQuery.newIntRange(
         field,
         min != null ? min.intValue() : null,
         max != null ? max.intValue() : null,
         minInc,
         maxInc);
   } else {
     throw new IllegalArgumentException("Unsupported numeric type " + clazz.getName());
   }
 }