@@ -351,13 +351,19 @@ public Float parse(XContentParser parser, boolean coerce) throws IOException {
351351 }
352352
353353 @ Override
354- public Query termQuery (String field , Object value , boolean isIndexed ) {
354+ public Query termQuery (String field , Object value , boolean isIndexed , boolean hasDocValues ) {
355355 float v = parseToFloat (value );
356356 if (Float .isFinite (HalfFloatPoint .sortableShortToHalfFloat (HalfFloatPoint .halfFloatToSortableShort (v ))) == false ) {
357357 return Queries .newMatchNoDocsQuery ("Value [" + value + "] is out of range" );
358358 }
359359
360360 if (isIndexed ) {
361+ if (hasDocValues ) {
362+ return new IndexOrDocValuesQuery (
363+ HalfFloatPoint .newExactQuery (field , v ),
364+ SortedNumericDocValuesField .newSlowExactQuery (field , HalfFloatPoint .halfFloatToSortableShort (v ))
365+ );
366+ }
361367 return HalfFloatPoint .newExactQuery (field , v );
362368 } else {
363369 return SortedNumericDocValuesField .newSlowExactQuery (field , HalfFloatPoint .halfFloatToSortableShort (v ));
@@ -541,13 +547,15 @@ public Float parse(XContentParser parser, boolean coerce) throws IOException {
541547 }
542548
543549 @ Override
544- public Query termQuery (String field , Object value , boolean isIndexed ) {
550+ public Query termQuery (String field , Object value , boolean isIndexed , boolean hasDocValues ) {
545551 float v = parseToFloat (value );
546552 if (Float .isFinite (v ) == false ) {
547553 return new MatchNoDocsQuery ("Value [" + value + "] is out of range" );
548554 }
549555
550- if (isIndexed ) {
556+ if (isIndexed && hasDocValues ) {
557+ return FloatField .newExactQuery (field , v );
558+ } else if (isIndexed ) {
551559 return FloatPoint .newExactQuery (field , v );
552560 } else {
553561 return SortedNumericDocValuesField .newSlowExactQuery (field , NumericUtils .floatToSortableInt (v ));
@@ -714,13 +722,15 @@ public FieldValues<Number> compile(String fieldName, Script script, ScriptCompil
714722 }
715723
716724 @ Override
717- public Query termQuery (String field , Object value , boolean isIndexed ) {
725+ public Query termQuery (String field , Object value , boolean isIndexed , boolean hasDocValues ) {
718726 double v = objectToDouble (value );
719727 if (Double .isFinite (v ) == false ) {
720728 return Queries .newMatchNoDocsQuery ("Value [" + value + "] has a decimal part" );
721729 }
722730
723- if (isIndexed ) {
731+ if (isIndexed && hasDocValues ) {
732+ return DoubleField .newExactQuery (field , v );
733+ } else if (isIndexed ) {
724734 return DoublePoint .newExactQuery (field , v );
725735 } else {
726736 return SortedNumericDocValuesField .newSlowExactQuery (field , NumericUtils .doubleToSortableLong (v ));
@@ -874,12 +884,12 @@ public Byte parse(XContentParser parser, boolean coerce) throws IOException {
874884 }
875885
876886 @ Override
877- public Query termQuery (String field , Object value , boolean isIndexed ) {
887+ public Query termQuery (String field , Object value , boolean isIndexed , boolean hasDocValues ) {
878888 if (isOutOfRange (value )) {
879889 return new MatchNoDocsQuery ("Value [" + value + "] is out of range" );
880890 }
881891
882- return INTEGER .termQuery (field , value , isIndexed );
892+ return INTEGER .termQuery (field , value , isIndexed , hasDocValues );
883893 }
884894
885895 @ Override
@@ -998,11 +1008,11 @@ public Short parse(XContentParser parser, boolean coerce) throws IOException {
9981008 }
9991009
10001010 @ Override
1001- public Query termQuery (String field , Object value , boolean isIndexed ) {
1011+ public Query termQuery (String field , Object value , boolean isIndexed , boolean hasDocValues ) {
10021012 if (isOutOfRange (value )) {
10031013 return Queries .newMatchNoDocsQuery ("Value [" + value + "] is out of range" );
10041014 }
1005- return INTEGER .termQuery (field , value , isIndexed );
1015+ return INTEGER .termQuery (field , value , isIndexed , hasDocValues );
10061016 }
10071017
10081018 @ Override
@@ -1124,7 +1134,7 @@ public Integer parse(XContentParser parser, boolean coerce) throws IOException {
11241134 }
11251135
11261136 @ Override
1127- public Query termQuery (String field , Object value , boolean isIndexed ) {
1137+ public Query termQuery (String field , Object value , boolean isIndexed , boolean hasDocValues ) {
11281138 if (hasDecimalPart (value )) {
11291139 return Queries .newMatchNoDocsQuery ("Value [" + value + "] has a decimal part" );
11301140 }
@@ -1135,7 +1145,9 @@ public Query termQuery(String field, Object value, boolean isIndexed) {
11351145 }
11361146 int v = parse (value , true );
11371147
1138- if (isIndexed ) {
1148+ if (isIndexed && hasDocValues ) {
1149+ return IntField .newExactQuery (field , v );
1150+ } else if (isIndexed ) {
11391151 return IntPoint .newExactQuery (field , v );
11401152 } else {
11411153 return SortedNumericDocValuesField .newSlowExactQuery (field , v );
@@ -1308,7 +1320,7 @@ public FieldValues<Number> compile(String fieldName, Script script, ScriptCompil
13081320 }
13091321
13101322 @ Override
1311- public Query termQuery (String field , Object value , boolean isIndexed ) {
1323+ public Query termQuery (String field , Object value , boolean isIndexed , boolean hasDocValues ) {
13121324 if (hasDecimalPart (value )) {
13131325 return Queries .newMatchNoDocsQuery ("Value [" + value + "] has a decimal part" );
13141326 }
@@ -1317,7 +1329,9 @@ public Query termQuery(String field, Object value, boolean isIndexed) {
13171329 }
13181330
13191331 long v = parse (value , true );
1320- if (isIndexed ) {
1332+ if (isIndexed && hasDocValues ) {
1333+ return LongField .newExactQuery (field , v );
1334+ } else if (isIndexed ) {
13211335 return LongPoint .newExactQuery (field , v );
13221336 } else {
13231337 return SortedNumericDocValuesField .newSlowExactQuery (field , v );
@@ -1500,7 +1514,7 @@ public final TypeParser parser() {
15001514 return parser ;
15011515 }
15021516
1503- public abstract Query termQuery (String field , Object value , boolean isIndexed );
1517+ public abstract Query termQuery (String field , Object value , boolean isIndexed , boolean hasDocValues );
15041518
15051519 public abstract Query termsQuery (String field , Collection <?> values );
15061520
@@ -1891,11 +1905,11 @@ public NumberFieldType(
18911905 }
18921906
18931907 public NumberFieldType (String name , NumberType type ) {
1894- this (name , type , true );
1908+ this (name , type , true , true );
18951909 }
18961910
1897- public NumberFieldType (String name , NumberType type , boolean isIndexed ) {
1898- this (name , type , isIndexed , false , true , true , null , Collections .emptyMap (), null , false , null , null , false );
1911+ public NumberFieldType (String name , NumberType type , boolean isIndexed , boolean hasDocValues ) {
1912+ this (name , type , isIndexed , false , hasDocValues , true , null , Collections .emptyMap (), null , false , null , null , false );
18991913 }
19001914
19011915 @ Override
@@ -1934,7 +1948,7 @@ public boolean isSearchable() {
19341948 @ Override
19351949 public Query termQuery (Object value , SearchExecutionContext context ) {
19361950 failIfNotIndexedNorDocValuesFallback (context );
1937- return type .termQuery (name (), value , isIndexed ());
1951+ return type .termQuery (name (), value , isIndexed (), hasDocValues () );
19381952 }
19391953
19401954 @ Override
0 commit comments