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