|
26 | 26 | import org.elasticsearch.common.xcontent.XContentHelper; |
27 | 27 | import org.elasticsearch.core.TimeValue; |
28 | 28 | import org.elasticsearch.index.fielddata.FieldData; |
| 29 | +import org.elasticsearch.index.fielddata.IndexFieldData; |
29 | 30 | import org.elasticsearch.index.fielddata.IndexGeoPointFieldData; |
30 | 31 | import org.elasticsearch.index.fielddata.IndexNumericFieldData; |
31 | 32 | import org.elasticsearch.index.fielddata.MultiGeoPointValues; |
|
35 | 36 | import org.elasticsearch.index.mapper.DateFieldMapper; |
36 | 37 | import org.elasticsearch.index.mapper.GeoPointFieldMapper.GeoPointFieldType; |
37 | 38 | import org.elasticsearch.index.mapper.MappedFieldType; |
38 | | -import org.elasticsearch.index.mapper.NumberFieldMapper; |
39 | 39 | import org.elasticsearch.index.query.SearchExecutionContext; |
40 | 40 | import org.elasticsearch.search.MultiValueMode; |
41 | 41 | import org.elasticsearch.xcontent.NamedXContentRegistry; |
@@ -217,15 +217,8 @@ private AbstractDistanceScoreFunction parseVariable( |
217 | 217 | return parseDateVariable(parser, context, fieldType, mode); |
218 | 218 | } else if (fieldType instanceof GeoPointFieldType) { |
219 | 219 | return parseGeoVariable(parser, context, fieldType, mode); |
220 | | - } else if (fieldType instanceof NumberFieldMapper.NumberFieldType) { |
221 | | - return parseNumberVariable(parser, context, fieldType, mode); |
222 | 220 | } else { |
223 | | - throw new ParsingException( |
224 | | - parser.getTokenLocation(), |
225 | | - "field [{}] is of type [{}], but only numeric types are supported.", |
226 | | - fieldName, |
227 | | - fieldType |
228 | | - ); |
| 221 | + return parseNumberVariable(parser, context, fieldType, mode); |
229 | 222 | } |
230 | 223 | } |
231 | 224 |
|
@@ -267,8 +260,15 @@ private AbstractDistanceScoreFunction parseNumberVariable( |
267 | 260 | DecayFunctionBuilder.ORIGIN |
268 | 261 | ); |
269 | 262 | } |
270 | | - IndexNumericFieldData numericFieldData = context.getForField(fieldType, MappedFieldType.FielddataOperation.SEARCH); |
271 | | - return new NumericFieldDataScoreFunction(origin, scale, decay, offset, getDecayFunction(), numericFieldData, mode); |
| 263 | + |
| 264 | + IndexFieldData<?> indexFieldData = context.getForField(fieldType, MappedFieldType.FielddataOperation.SEARCH); |
| 265 | + if (indexFieldData instanceof IndexNumericFieldData numericFieldData) { |
| 266 | + return new NumericFieldDataScoreFunction(origin, scale, decay, offset, getDecayFunction(), numericFieldData, mode); |
| 267 | + } else { |
| 268 | + throw new IllegalArgumentException( |
| 269 | + "field [" + fieldName + "] is of type [" + fieldType + "], but only numeric types are supported." |
| 270 | + ); |
| 271 | + } |
272 | 272 | } |
273 | 273 |
|
274 | 274 | private AbstractDistanceScoreFunction parseGeoVariable( |
|
0 commit comments