@@ -351,13 +351,19 @@ public Float parse(XContentParser parser, boolean coerce) throws IOException {
351
351
}
352
352
353
353
@ Override
354
- public Query termQuery (String field , Object value , boolean isIndexed ) {
354
+ public Query termQuery (String field , Object value , boolean isIndexed , boolean hasDocValues ) {
355
355
float v = parseToFloat (value );
356
356
if (Float .isFinite (HalfFloatPoint .sortableShortToHalfFloat (HalfFloatPoint .halfFloatToSortableShort (v ))) == false ) {
357
357
return Queries .newMatchNoDocsQuery ("Value [" + value + "] is out of range" );
358
358
}
359
359
360
360
if (isIndexed ) {
361
+ if (hasDocValues ) {
362
+ return new IndexOrDocValuesQuery (
363
+ HalfFloatPoint .newExactQuery (field , v ),
364
+ SortedNumericDocValuesField .newSlowExactQuery (field , HalfFloatPoint .halfFloatToSortableShort (v ))
365
+ );
366
+ }
361
367
return HalfFloatPoint .newExactQuery (field , v );
362
368
} else {
363
369
return SortedNumericDocValuesField .newSlowExactQuery (field , HalfFloatPoint .halfFloatToSortableShort (v ));
@@ -541,13 +547,15 @@ public Float parse(XContentParser parser, boolean coerce) throws IOException {
541
547
}
542
548
543
549
@ Override
544
- public Query termQuery (String field , Object value , boolean isIndexed ) {
550
+ public Query termQuery (String field , Object value , boolean isIndexed , boolean hasDocValues ) {
545
551
float v = parseToFloat (value );
546
552
if (Float .isFinite (v ) == false ) {
547
553
return new MatchNoDocsQuery ("Value [" + value + "] is out of range" );
548
554
}
549
555
550
- if (isIndexed ) {
556
+ if (isIndexed && hasDocValues ) {
557
+ return FloatField .newExactQuery (field , v );
558
+ } else if (isIndexed ) {
551
559
return FloatPoint .newExactQuery (field , v );
552
560
} else {
553
561
return SortedNumericDocValuesField .newSlowExactQuery (field , NumericUtils .floatToSortableInt (v ));
@@ -714,13 +722,15 @@ public FieldValues<Number> compile(String fieldName, Script script, ScriptCompil
714
722
}
715
723
716
724
@ Override
717
- public Query termQuery (String field , Object value , boolean isIndexed ) {
725
+ public Query termQuery (String field , Object value , boolean isIndexed , boolean hasDocValues ) {
718
726
double v = objectToDouble (value );
719
727
if (Double .isFinite (v ) == false ) {
720
728
return Queries .newMatchNoDocsQuery ("Value [" + value + "] has a decimal part" );
721
729
}
722
730
723
- if (isIndexed ) {
731
+ if (isIndexed && hasDocValues ) {
732
+ return DoubleField .newExactQuery (field , v );
733
+ } else if (isIndexed ) {
724
734
return DoublePoint .newExactQuery (field , v );
725
735
} else {
726
736
return SortedNumericDocValuesField .newSlowExactQuery (field , NumericUtils .doubleToSortableLong (v ));
@@ -874,12 +884,12 @@ public Byte parse(XContentParser parser, boolean coerce) throws IOException {
874
884
}
875
885
876
886
@ Override
877
- public Query termQuery (String field , Object value , boolean isIndexed ) {
887
+ public Query termQuery (String field , Object value , boolean isIndexed , boolean hasDocValues ) {
878
888
if (isOutOfRange (value )) {
879
889
return new MatchNoDocsQuery ("Value [" + value + "] is out of range" );
880
890
}
881
891
882
- return INTEGER .termQuery (field , value , isIndexed );
892
+ return INTEGER .termQuery (field , value , isIndexed , hasDocValues );
883
893
}
884
894
885
895
@ Override
@@ -998,11 +1008,11 @@ public Short parse(XContentParser parser, boolean coerce) throws IOException {
998
1008
}
999
1009
1000
1010
@ Override
1001
- public Query termQuery (String field , Object value , boolean isIndexed ) {
1011
+ public Query termQuery (String field , Object value , boolean isIndexed , boolean hasDocValues ) {
1002
1012
if (isOutOfRange (value )) {
1003
1013
return Queries .newMatchNoDocsQuery ("Value [" + value + "] is out of range" );
1004
1014
}
1005
- return INTEGER .termQuery (field , value , isIndexed );
1015
+ return INTEGER .termQuery (field , value , isIndexed , hasDocValues );
1006
1016
}
1007
1017
1008
1018
@ Override
@@ -1124,7 +1134,7 @@ public Integer parse(XContentParser parser, boolean coerce) throws IOException {
1124
1134
}
1125
1135
1126
1136
@ Override
1127
- public Query termQuery (String field , Object value , boolean isIndexed ) {
1137
+ public Query termQuery (String field , Object value , boolean isIndexed , boolean hasDocValues ) {
1128
1138
if (hasDecimalPart (value )) {
1129
1139
return Queries .newMatchNoDocsQuery ("Value [" + value + "] has a decimal part" );
1130
1140
}
@@ -1135,7 +1145,9 @@ public Query termQuery(String field, Object value, boolean isIndexed) {
1135
1145
}
1136
1146
int v = parse (value , true );
1137
1147
1138
- if (isIndexed ) {
1148
+ if (isIndexed && hasDocValues ) {
1149
+ return IntField .newExactQuery (field , v );
1150
+ } else if (isIndexed ) {
1139
1151
return IntPoint .newExactQuery (field , v );
1140
1152
} else {
1141
1153
return SortedNumericDocValuesField .newSlowExactQuery (field , v );
@@ -1308,7 +1320,7 @@ public FieldValues<Number> compile(String fieldName, Script script, ScriptCompil
1308
1320
}
1309
1321
1310
1322
@ Override
1311
- public Query termQuery (String field , Object value , boolean isIndexed ) {
1323
+ public Query termQuery (String field , Object value , boolean isIndexed , boolean hasDocValues ) {
1312
1324
if (hasDecimalPart (value )) {
1313
1325
return Queries .newMatchNoDocsQuery ("Value [" + value + "] has a decimal part" );
1314
1326
}
@@ -1317,7 +1329,9 @@ public Query termQuery(String field, Object value, boolean isIndexed) {
1317
1329
}
1318
1330
1319
1331
long v = parse (value , true );
1320
- if (isIndexed ) {
1332
+ if (isIndexed && hasDocValues ) {
1333
+ return LongField .newExactQuery (field , v );
1334
+ } else if (isIndexed ) {
1321
1335
return LongPoint .newExactQuery (field , v );
1322
1336
} else {
1323
1337
return SortedNumericDocValuesField .newSlowExactQuery (field , v );
@@ -1500,7 +1514,7 @@ public final TypeParser parser() {
1500
1514
return parser ;
1501
1515
}
1502
1516
1503
- public abstract Query termQuery (String field , Object value , boolean isIndexed );
1517
+ public abstract Query termQuery (String field , Object value , boolean isIndexed , boolean hasDocValues );
1504
1518
1505
1519
public abstract Query termsQuery (String field , Collection <?> values );
1506
1520
@@ -1891,11 +1905,11 @@ public NumberFieldType(
1891
1905
}
1892
1906
1893
1907
public NumberFieldType (String name , NumberType type ) {
1894
- this (name , type , true );
1908
+ this (name , type , true , true );
1895
1909
}
1896
1910
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 );
1899
1913
}
1900
1914
1901
1915
@ Override
@@ -1934,7 +1948,7 @@ public boolean isSearchable() {
1934
1948
@ Override
1935
1949
public Query termQuery (Object value , SearchExecutionContext context ) {
1936
1950
failIfNotIndexedNorDocValuesFallback (context );
1937
- return type .termQuery (name (), value , isIndexed ());
1951
+ return type .termQuery (name (), value , isIndexed (), hasDocValues () );
1938
1952
}
1939
1953
1940
1954
@ Override
0 commit comments