@@ -352,13 +352,19 @@ public Float parse(XContentParser parser, boolean coerce) throws IOException {
352352 }
353353
354354 @ Override
355- public Query termQuery (String field , Object value , boolean isIndexed ) {
355+ public Query termQuery (String field , Object value , boolean isIndexed , boolean hasDocValues ) {
356356 float v = parseToFloat (value );
357357 if (Float .isFinite (HalfFloatPoint .sortableShortToHalfFloat (HalfFloatPoint .halfFloatToSortableShort (v ))) == false ) {
358358 return Queries .newMatchNoDocsQuery ("Value [" + value + "] is out of range" );
359359 }
360360
361361 if (isIndexed ) {
362+ if (hasDocValues ) {
363+ return new IndexOrDocValuesQuery (
364+ HalfFloatPoint .newExactQuery (field , v ),
365+ SortedNumericDocValuesField .newSlowExactQuery (field , HalfFloatPoint .halfFloatToSortableShort (v ))
366+ );
367+ }
362368 return HalfFloatPoint .newExactQuery (field , v );
363369 } else {
364370 return SortedNumericDocValuesField .newSlowExactQuery (field , HalfFloatPoint .halfFloatToSortableShort (v ));
@@ -542,13 +548,15 @@ public Float parse(XContentParser parser, boolean coerce) throws IOException {
542548 }
543549
544550 @ Override
545- public Query termQuery (String field , Object value , boolean isIndexed ) {
551+ public Query termQuery (String field , Object value , boolean isIndexed , boolean hasDocValues ) {
546552 float v = parseToFloat (value );
547553 if (Float .isFinite (v ) == false ) {
548554 return new MatchNoDocsQuery ("Value [" + value + "] is out of range" );
549555 }
550556
551- if (isIndexed ) {
557+ if (isIndexed && hasDocValues ) {
558+ return FloatField .newExactQuery (field , v );
559+ } else if (isIndexed ) {
552560 return FloatPoint .newExactQuery (field , v );
553561 } else {
554562 return SortedNumericDocValuesField .newSlowExactQuery (field , NumericUtils .floatToSortableInt (v ));
@@ -715,13 +723,15 @@ public FieldValues<Number> compile(String fieldName, Script script, ScriptCompil
715723 }
716724
717725 @ Override
718- public Query termQuery (String field , Object value , boolean isIndexed ) {
726+ public Query termQuery (String field , Object value , boolean isIndexed , boolean hasDocValues ) {
719727 double v = objectToDouble (value );
720728 if (Double .isFinite (v ) == false ) {
721729 return Queries .newMatchNoDocsQuery ("Value [" + value + "] has a decimal part" );
722730 }
723731
724- if (isIndexed ) {
732+ if (isIndexed && hasDocValues ) {
733+ return DoubleField .newExactQuery (field , v );
734+ } else if (isIndexed ) {
725735 return DoublePoint .newExactQuery (field , v );
726736 } else {
727737 return SortedNumericDocValuesField .newSlowExactQuery (field , NumericUtils .doubleToSortableLong (v ));
@@ -875,12 +885,12 @@ public Byte parse(XContentParser parser, boolean coerce) throws IOException {
875885 }
876886
877887 @ Override
878- public Query termQuery (String field , Object value , boolean isIndexed ) {
888+ public Query termQuery (String field , Object value , boolean isIndexed , boolean hasDocValues ) {
879889 if (isOutOfRange (value )) {
880890 return new MatchNoDocsQuery ("Value [" + value + "] is out of range" );
881891 }
882892
883- return INTEGER .termQuery (field , value , isIndexed );
893+ return INTEGER .termQuery (field , value , isIndexed , hasDocValues );
884894 }
885895
886896 @ Override
@@ -999,11 +1009,11 @@ public Short parse(XContentParser parser, boolean coerce) throws IOException {
9991009 }
10001010
10011011 @ Override
1002- public Query termQuery (String field , Object value , boolean isIndexed ) {
1012+ public Query termQuery (String field , Object value , boolean isIndexed , boolean hasDocValues ) {
10031013 if (isOutOfRange (value )) {
10041014 return Queries .newMatchNoDocsQuery ("Value [" + value + "] is out of range" );
10051015 }
1006- return INTEGER .termQuery (field , value , isIndexed );
1016+ return INTEGER .termQuery (field , value , isIndexed , hasDocValues );
10071017 }
10081018
10091019 @ Override
@@ -1125,7 +1135,7 @@ public Integer parse(XContentParser parser, boolean coerce) throws IOException {
11251135 }
11261136
11271137 @ Override
1128- public Query termQuery (String field , Object value , boolean isIndexed ) {
1138+ public Query termQuery (String field , Object value , boolean isIndexed , boolean hasDocValues ) {
11291139 if (hasDecimalPart (value )) {
11301140 return Queries .newMatchNoDocsQuery ("Value [" + value + "] has a decimal part" );
11311141 }
@@ -1136,7 +1146,9 @@ public Query termQuery(String field, Object value, boolean isIndexed) {
11361146 }
11371147 int v = parse (value , true );
11381148
1139- if (isIndexed ) {
1149+ if (isIndexed && hasDocValues ) {
1150+ return IntField .newExactQuery (field , v );
1151+ } else if (isIndexed ) {
11401152 return IntPoint .newExactQuery (field , v );
11411153 } else {
11421154 return SortedNumericDocValuesField .newSlowExactQuery (field , v );
@@ -1309,7 +1321,7 @@ public FieldValues<Number> compile(String fieldName, Script script, ScriptCompil
13091321 }
13101322
13111323 @ Override
1312- public Query termQuery (String field , Object value , boolean isIndexed ) {
1324+ public Query termQuery (String field , Object value , boolean isIndexed , boolean hasDocValues ) {
13131325 if (hasDecimalPart (value )) {
13141326 return Queries .newMatchNoDocsQuery ("Value [" + value + "] has a decimal part" );
13151327 }
@@ -1318,7 +1330,9 @@ public Query termQuery(String field, Object value, boolean isIndexed) {
13181330 }
13191331
13201332 long v = parse (value , true );
1321- if (isIndexed ) {
1333+ if (isIndexed && hasDocValues ) {
1334+ return LongField .newExactQuery (field , v );
1335+ } else if (isIndexed ) {
13221336 return LongPoint .newExactQuery (field , v );
13231337 } else {
13241338 return SortedNumericDocValuesField .newSlowExactQuery (field , v );
@@ -1502,7 +1516,7 @@ public final TypeParser parser() {
15021516 return parser ;
15031517 }
15041518
1505- public abstract Query termQuery (String field , Object value , boolean isIndexed );
1519+ public abstract Query termQuery (String field , Object value , boolean isIndexed , boolean hasDocValues );
15061520
15071521 public abstract Query termsQuery (String field , Collection <?> values );
15081522
@@ -1893,11 +1907,11 @@ public NumberFieldType(
18931907 }
18941908
18951909 public NumberFieldType (String name , NumberType type ) {
1896- this (name , type , true );
1910+ this (name , type , true , true );
18971911 }
18981912
1899- public NumberFieldType (String name , NumberType type , boolean isIndexed ) {
1900- this (name , type , isIndexed , false , true , true , null , Collections .emptyMap (), null , false , null , null , false );
1913+ public NumberFieldType (String name , NumberType type , boolean isIndexed , boolean hasDocValues ) {
1914+ this (name , type , isIndexed , false , hasDocValues , true , null , Collections .emptyMap (), null , false , null , null , false );
19011915 }
19021916
19031917 @ Override
@@ -1936,7 +1950,7 @@ public boolean isSearchable() {
19361950 @ Override
19371951 public Query termQuery (Object value , SearchExecutionContext context ) {
19381952 failIfNotIndexedNorDocValuesFallback (context );
1939- return type .termQuery (name (), value , isIndexed ());
1953+ return type .termQuery (name (), value , isIndexed (), hasDocValues () );
19401954 }
19411955
19421956 @ Override
0 commit comments