diff --git a/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/RankFeatureFieldMapper.java b/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/RankFeatureFieldMapper.java index 4e58cee6408..a64e5ae1901 100644 --- a/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/RankFeatureFieldMapper.java +++ b/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/RankFeatureFieldMapper.java @@ -118,7 +118,7 @@ public class RankFeatureFieldMapper extends ParametrizedFieldMapper { if (format != null) { throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats."); } - return new SourceValueFetcher(name(), mapperService, false) { + return new SourceValueFetcher(name(), mapperService) { @Override protected Float parseSourceValue(Object value) { return objectToFloat(value); diff --git a/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/RankFeaturesFieldMapper.java b/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/RankFeaturesFieldMapper.java index 5c292275c0c..b15929da68c 100644 --- a/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/RankFeaturesFieldMapper.java +++ b/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/RankFeaturesFieldMapper.java @@ -93,7 +93,7 @@ public class RankFeaturesFieldMapper extends ParametrizedFieldMapper { if (format != null) { throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats."); } - return new SourceValueFetcher(name(), mapperService, false) { + return new SourceValueFetcher(name(), mapperService) { @Override protected Object parseSourceValue(Object value) { return value; diff --git a/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapper.java b/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapper.java index 7e54971b542..9718cde1a18 100644 --- a/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapper.java +++ b/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapper.java @@ -225,7 +225,7 @@ public class ScaledFloatFieldMapper extends ParametrizedFieldMapper { if (format != null) { throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats."); } - return new SourceValueFetcher(name(), mapperService, false) { + return new SourceValueFetcher(name(), mapperService) { @Override protected Double parseSourceValue(Object value) { double doubleValue; diff --git a/modules/parent-join/src/main/java/org/elasticsearch/join/mapper/ParentJoinFieldMapper.java b/modules/parent-join/src/main/java/org/elasticsearch/join/mapper/ParentJoinFieldMapper.java index 82e8e57f91e..3fb70acc54c 100644 --- a/modules/parent-join/src/main/java/org/elasticsearch/join/mapper/ParentJoinFieldMapper.java +++ b/modules/parent-join/src/main/java/org/elasticsearch/join/mapper/ParentJoinFieldMapper.java @@ -227,7 +227,7 @@ public final class ParentJoinFieldMapper extends FieldMapper { if (format != null) { throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats."); } - return new SourceValueFetcher(name(), mapperService, false) { + return new SourceValueFetcher(name(), mapperService) { @Override protected Object parseSourceValue(Object value) { return value; diff --git a/modules/percolator/src/main/java/org/elasticsearch/percolator/PercolatorFieldMapper.java b/modules/percolator/src/main/java/org/elasticsearch/percolator/PercolatorFieldMapper.java index 8025c7fc6f3..83aa99badb3 100644 --- a/modules/percolator/src/main/java/org/elasticsearch/percolator/PercolatorFieldMapper.java +++ b/modules/percolator/src/main/java/org/elasticsearch/percolator/PercolatorFieldMapper.java @@ -229,7 +229,7 @@ public class PercolatorFieldMapper extends ParametrizedFieldMapper { if (format != null) { throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats."); } - return new SourceValueFetcher(name(), mapperService, false) { + return new SourceValueFetcher(name(), mapperService) { @Override protected Object parseSourceValue(Object value) { return value; diff --git a/plugins/analysis-icu/src/main/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapper.java b/plugins/analysis-icu/src/main/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapper.java index d27f4c90345..1cb32a5612e 100644 --- a/plugins/analysis-icu/src/main/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapper.java +++ b/plugins/analysis-icu/src/main/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapper.java @@ -104,7 +104,7 @@ public class ICUCollationKeywordFieldMapper extends FieldMapper { throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats."); } - return new SourceValueFetcher(name(), mapperService, false, nullValue) { + return new SourceValueFetcher(name(), mapperService, nullValue) { @Override protected String parseSourceValue(Object value) { String keywordValue = value.toString(); diff --git a/plugins/mapper-murmur3/src/main/java/org/elasticsearch/index/mapper/murmur3/Murmur3FieldMapper.java b/plugins/mapper-murmur3/src/main/java/org/elasticsearch/index/mapper/murmur3/Murmur3FieldMapper.java index 477c0584fb8..9e1b38d62ec 100644 --- a/plugins/mapper-murmur3/src/main/java/org/elasticsearch/index/mapper/murmur3/Murmur3FieldMapper.java +++ b/plugins/mapper-murmur3/src/main/java/org/elasticsearch/index/mapper/murmur3/Murmur3FieldMapper.java @@ -111,7 +111,7 @@ public class Murmur3FieldMapper extends ParametrizedFieldMapper { if (format != null) { throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats."); } - return new SourceValueFetcher(name(), mapperService, false) { + return new SourceValueFetcher(name(), mapperService) { @Override protected String parseSourceValue(Object value) { return value.toString(); diff --git a/server/src/main/java/org/elasticsearch/index/mapper/AbstractGeometryFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/AbstractGeometryFieldMapper.java index 7ddaeceb660..7bf454dad1b 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/AbstractGeometryFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/AbstractGeometryFieldMapper.java @@ -259,13 +259,21 @@ public abstract class AbstractGeometryFieldMapper extends Fie String geoFormat = format != null ? format : GeoJsonGeometryFormat.NAME; Function valueParser = value -> geometryParser.parseAndFormatObject(value, geoFormat); - - return new SourceValueFetcher(name(), mapperService, parsesArrayValue) { - @Override - protected Object parseSourceValue(Object value) { - return valueParser.apply(value); - } - }; + if (parsesArrayValue) { + return new ArraySourceValueFetcher(name(), mapperService) { + @Override + protected Object parseSourceValue(Object value) { + return valueParser.apply(value); + } + }; + } else { + return new SourceValueFetcher(name(), mapperService) { + @Override + protected Object parseSourceValue(Object value) { + return valueParser.apply(value); + } + }; + } } } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/ArraySourceValueFetcher.java b/server/src/main/java/org/elasticsearch/index/mapper/ArraySourceValueFetcher.java new file mode 100644 index 00000000000..dab9656662d --- /dev/null +++ b/server/src/main/java/org/elasticsearch/index/mapper/ArraySourceValueFetcher.java @@ -0,0 +1,74 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.index.mapper; + +import org.elasticsearch.common.Nullable; +import org.elasticsearch.search.lookup.SourceLookup; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +/** + * An implementation of {@link ValueFetcher} that knows how to extract values + * from the document source. + * + * This class differs from {@link SourceValueFetcher} in that it directly handles + * array values in parsing. Field types should use this class if their corresponding + * mapper returns true for {@link FieldMapper#parsesArrayValue()}. + */ +public abstract class ArraySourceValueFetcher implements ValueFetcher { + private final Set sourcePaths; + private final @Nullable Object nullValue; + + public ArraySourceValueFetcher(String fieldName, MapperService mapperService) { + this(fieldName, mapperService, null); + } + + /** + * @param fieldName The name of the field. + * @param mapperService A mapper service. + * @param nullValue A optional substitute value if the _source value is 'null'. + */ + public ArraySourceValueFetcher(String fieldName, MapperService mapperService, Object nullValue) { + this.sourcePaths = mapperService.sourcePath(fieldName); + this.nullValue = nullValue; + } + + @Override + public List fetchValues(SourceLookup lookup) { + List values = new ArrayList<>(); + for (String path : sourcePaths) { + Object sourceValue = lookup.extractValue(path, nullValue); + if (sourceValue == null) { + return org.elasticsearch.common.collect.List.of(); + } + values.addAll((List) parseSourceValue(sourceValue)); + } + return values; + } + + /** + * Given a value that has been extracted from a document's source, parse it into a standard + * format. This parsing logic should closely mirror the value parsing in + * {@link FieldMapper#parseCreateField} or {@link FieldMapper#parse}. + */ + protected abstract Object parseSourceValue(Object value); +} diff --git a/server/src/main/java/org/elasticsearch/index/mapper/BinaryFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/BinaryFieldMapper.java index c66306948d3..a6d6305031d 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/BinaryFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/BinaryFieldMapper.java @@ -103,7 +103,7 @@ public class BinaryFieldMapper extends ParametrizedFieldMapper { if (format != null) { throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats."); } - return new SourceValueFetcher(name(), mapperService, false) { + return new SourceValueFetcher(name(), mapperService) { @Override protected Object parseSourceValue(Object value) { return value; diff --git a/server/src/main/java/org/elasticsearch/index/mapper/BooleanFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/BooleanFieldMapper.java index 0486d9ed17e..0cbb287cfd0 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/BooleanFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/BooleanFieldMapper.java @@ -135,7 +135,7 @@ public class BooleanFieldMapper extends ParametrizedFieldMapper { throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats."); } - return new SourceValueFetcher(name(), mapperService, false, nullValue) { + return new SourceValueFetcher(name(), mapperService, nullValue) { @Override protected Boolean parseSourceValue(Object value) { if (value instanceof Boolean) { diff --git a/server/src/main/java/org/elasticsearch/index/mapper/CompletionFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/CompletionFieldMapper.java index 2a95f610782..481153706d3 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/CompletionFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/CompletionFieldMapper.java @@ -307,7 +307,7 @@ public class CompletionFieldMapper extends ParametrizedFieldMapper { throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats."); } - return new SourceValueFetcher(name(), mapperService, true) { + return new ArraySourceValueFetcher(name(), mapperService) { @Override protected List parseSourceValue(Object value) { if (value instanceof List) { diff --git a/server/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java index e4b4615f38e..635ba77eeab 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java @@ -330,7 +330,7 @@ public final class DateFieldMapper extends ParametrizedFieldMapper { ? DateFormatter.forPattern(format).withLocale(defaultFormatter.locale()) : defaultFormatter; - return new SourceValueFetcher(name(), mapperService, false, nullValue) { + return new SourceValueFetcher(name(), mapperService, nullValue) { @Override public String parseSourceValue(Object value) { String date = value.toString(); diff --git a/server/src/main/java/org/elasticsearch/index/mapper/IpFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/IpFieldMapper.java index a8103b2644a..270f82b0a6e 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/IpFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/IpFieldMapper.java @@ -158,7 +158,7 @@ public class IpFieldMapper extends ParametrizedFieldMapper { if (format != null) { throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats."); } - return new SourceValueFetcher(name(), mapperService, false, nullValue) { + return new SourceValueFetcher(name(), mapperService, nullValue) { @Override protected Object parseSourceValue(Object value) { InetAddress address; diff --git a/server/src/main/java/org/elasticsearch/index/mapper/KeywordFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/KeywordFieldMapper.java index da5fda108e3..4d2e55d97d6 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/KeywordFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/KeywordFieldMapper.java @@ -243,7 +243,7 @@ public final class KeywordFieldMapper extends ParametrizedFieldMapper { throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats."); } - return new SourceValueFetcher(name(), mapperService, false, nullValue) { + return new SourceValueFetcher(name(), mapperService, nullValue) { @Override protected String parseSourceValue(Object value) { String keywordValue = value.toString(); diff --git a/server/src/main/java/org/elasticsearch/index/mapper/NumberFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/NumberFieldMapper.java index ccbe9dbd088..da7b9e1b84b 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/NumberFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/NumberFieldMapper.java @@ -980,7 +980,7 @@ public class NumberFieldMapper extends ParametrizedFieldMapper { throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats."); } - return new SourceValueFetcher(name(), mapperService, false, nullValue) { + return new SourceValueFetcher(name(), mapperService, nullValue) { @Override protected Object parseSourceValue(Object value) { if (value.equals("")) { diff --git a/server/src/main/java/org/elasticsearch/index/mapper/RangeFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/RangeFieldMapper.java index a7d560918a6..1cd44370eeb 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/RangeFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/RangeFieldMapper.java @@ -205,7 +205,7 @@ public class RangeFieldMapper extends ParametrizedFieldMapper { ? DateFormatter.forPattern(format).withLocale(defaultFormatter.locale()) : defaultFormatter; - return new SourceValueFetcher(name(), mapperService, false) { + return new SourceValueFetcher(name(), mapperService) { @Override @SuppressWarnings("unchecked") diff --git a/server/src/main/java/org/elasticsearch/index/mapper/SourceValueFetcher.java b/server/src/main/java/org/elasticsearch/index/mapper/SourceValueFetcher.java index 016606d36d5..aa0b4dbfc1c 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/SourceValueFetcher.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/SourceValueFetcher.java @@ -32,25 +32,25 @@ import java.util.Set; * An implementation of {@link ValueFetcher} that knows how to extract values * from the document source. Most standard field mappers will use this class * to implement value fetching. + * + * Field types that handle arrays directly should instead use {@link ArraySourceValueFetcher}. */ public abstract class SourceValueFetcher implements ValueFetcher { private final Set sourcePaths; private final @Nullable Object nullValue; - private final boolean parsesArrayValue; - public SourceValueFetcher(String fieldName, MapperService mapperService, boolean parsesArrayValue) { - this(fieldName, mapperService, parsesArrayValue, null); + public SourceValueFetcher(String fieldName, MapperService mapperService) { + this(fieldName, mapperService, null); } /** * @param fieldName The name of the field. - * @param parsesArrayValue Whether the fetcher handles array values during document parsing. + * @param mapperService A mapper service. * @param nullValue A optional substitute value if the _source value is 'null'. */ - public SourceValueFetcher(String fieldName, MapperService mapperService, boolean parsesArrayValue, Object nullValue) { + public SourceValueFetcher(String fieldName, MapperService mapperService, Object nullValue) { this.sourcePaths = mapperService.sourcePath(fieldName); this.nullValue = nullValue; - this.parsesArrayValue = parsesArrayValue; } @Override @@ -62,22 +62,18 @@ public abstract class SourceValueFetcher implements ValueFetcher { return org.elasticsearch.common.collect.List.of(); } - if (parsesArrayValue) { - values.addAll((List) parseSourceValue(sourceValue)); - } else { - // We allow source values to contain multiple levels of arrays, such as `"field": [[1, 2]]`. - // So we need to unwrap these arrays before passing them on to be parsed. - Queue queue = new ArrayDeque<>(); - queue.add(sourceValue); - while (queue.isEmpty() == false) { - Object value = queue.poll(); - if (value instanceof List) { - queue.addAll((List) value); - } else { - Object parsedValue = parseSourceValue(value); - if (parsedValue != null) { - values.add(parsedValue); - } + // We allow source values to contain multiple levels of arrays, such as `"field": [[1, 2]]`. + // So we need to unwrap these arrays before passing them on to be parsed. + Queue queue = new ArrayDeque<>(); + queue.add(sourceValue); + while (queue.isEmpty() == false) { + Object value = queue.poll(); + if (value instanceof List) { + queue.addAll((List) value); + } else { + Object parsedValue = parseSourceValue(value); + if (parsedValue != null) { + values.add(parsedValue); } } } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java index 6630f24e379..97138c5a3aa 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java @@ -645,7 +645,7 @@ public class TextFieldMapper extends FieldMapper { if (format != null) { throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats."); } - return new SourceValueFetcher(name(), mapperService, false) { + return new SourceValueFetcher(name(), mapperService) { @Override protected Object parseSourceValue(Object value) { return value.toString(); diff --git a/server/src/test/java/org/elasticsearch/index/mapper/ExternalMapper.java b/server/src/test/java/org/elasticsearch/index/mapper/ExternalMapper.java index acbc802d8ca..d827ddb57d2 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/ExternalMapper.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/ExternalMapper.java @@ -107,7 +107,7 @@ public class ExternalMapper extends ParametrizedFieldMapper { @Override public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searchLookup, String format) { - return new SourceValueFetcher(name(), mapperService, false) { + return new SourceValueFetcher(name(), mapperService) { @Override protected Object parseSourceValue(Object value) { return value; diff --git a/server/src/test/java/org/elasticsearch/index/mapper/FakeStringFieldMapper.java b/server/src/test/java/org/elasticsearch/index/mapper/FakeStringFieldMapper.java index 640fdcddad7..b6673735374 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/FakeStringFieldMapper.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/FakeStringFieldMapper.java @@ -95,7 +95,7 @@ public class FakeStringFieldMapper extends FieldMapper { @Override public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searchLookup, String format) { - return new SourceValueFetcher(name(), mapperService, false) { + return new SourceValueFetcher(name(), mapperService) { @Override protected String parseSourceValue(Object value) { return value.toString(); diff --git a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/mapper/HistogramFieldMapper.java b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/mapper/HistogramFieldMapper.java index 0eb235905e9..38901eb2f71 100644 --- a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/mapper/HistogramFieldMapper.java +++ b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/mapper/HistogramFieldMapper.java @@ -141,7 +141,7 @@ public class HistogramFieldMapper extends ParametrizedFieldMapper { if (format != null) { throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats."); } - return new SourceValueFetcher(name(), mapperService, false) { + return new SourceValueFetcher(name(), mapperService) { @Override protected Object parseSourceValue(Object value) { return value; diff --git a/x-pack/plugin/mapper-flattened/src/main/java/org/elasticsearch/xpack/flattened/mapper/FlatObjectFieldMapper.java b/x-pack/plugin/mapper-flattened/src/main/java/org/elasticsearch/xpack/flattened/mapper/FlatObjectFieldMapper.java index 32acbae7e93..9e0e06ff060 100644 --- a/x-pack/plugin/mapper-flattened/src/main/java/org/elasticsearch/xpack/flattened/mapper/FlatObjectFieldMapper.java +++ b/x-pack/plugin/mapper-flattened/src/main/java/org/elasticsearch/xpack/flattened/mapper/FlatObjectFieldMapper.java @@ -479,7 +479,7 @@ public final class FlatObjectFieldMapper extends DynamicKeyFieldMapper { if (format != null) { throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats."); } - return new SourceValueFetcher(name(), mapperService, false, nullValue) { + return new SourceValueFetcher(name(), mapperService, nullValue) { @Override protected Object parseSourceValue(Object value) { return value; diff --git a/x-pack/plugin/mapper-unsigned-long/src/main/java/org/elasticsearch/xpack/unsignedlong/UnsignedLongFieldMapper.java b/x-pack/plugin/mapper-unsigned-long/src/main/java/org/elasticsearch/xpack/unsignedlong/UnsignedLongFieldMapper.java index bfb2170a73f..c64073fd218 100644 --- a/x-pack/plugin/mapper-unsigned-long/src/main/java/org/elasticsearch/xpack/unsignedlong/UnsignedLongFieldMapper.java +++ b/x-pack/plugin/mapper-unsigned-long/src/main/java/org/elasticsearch/xpack/unsignedlong/UnsignedLongFieldMapper.java @@ -235,7 +235,7 @@ public class UnsignedLongFieldMapper extends ParametrizedFieldMapper { throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats."); } - return new SourceValueFetcher(name(), mapperService, false, nullValueFormatted) { + return new SourceValueFetcher(name(), mapperService, nullValueFormatted) { @Override protected Object parseSourceValue(Object value) { if (value.equals("")) { diff --git a/x-pack/plugin/mapper-version/src/main/java/org/elasticsearch/xpack/versionfield/VersionStringFieldMapper.java b/x-pack/plugin/mapper-version/src/main/java/org/elasticsearch/xpack/versionfield/VersionStringFieldMapper.java index 55c2f03e84e..49975516b6a 100644 --- a/x-pack/plugin/mapper-version/src/main/java/org/elasticsearch/xpack/versionfield/VersionStringFieldMapper.java +++ b/x-pack/plugin/mapper-version/src/main/java/org/elasticsearch/xpack/versionfield/VersionStringFieldMapper.java @@ -138,7 +138,7 @@ public class VersionStringFieldMapper extends ParametrizedFieldMapper { throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats."); } - return new SourceValueFetcher(name(), mapperService, false, null) { + return new SourceValueFetcher(name(), mapperService, null) { @Override protected String parseSourceValue(Object value) { return value.toString(); diff --git a/x-pack/plugin/vectors/src/main/java/org/elasticsearch/xpack/vectors/mapper/DenseVectorFieldMapper.java b/x-pack/plugin/vectors/src/main/java/org/elasticsearch/xpack/vectors/mapper/DenseVectorFieldMapper.java index 4bae4f99ac3..c65ce8c24cc 100644 --- a/x-pack/plugin/vectors/src/main/java/org/elasticsearch/xpack/vectors/mapper/DenseVectorFieldMapper.java +++ b/x-pack/plugin/vectors/src/main/java/org/elasticsearch/xpack/vectors/mapper/DenseVectorFieldMapper.java @@ -15,13 +15,13 @@ import org.elasticsearch.Version; import org.elasticsearch.common.xcontent.XContentParser.Token; import org.elasticsearch.common.xcontent.support.XContentMapValues; import org.elasticsearch.index.fielddata.IndexFieldData; +import org.elasticsearch.index.mapper.ArraySourceValueFetcher; import org.elasticsearch.index.mapper.FieldMapper; import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.mapper.MapperParsingException; import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.mapper.ParametrizedFieldMapper; import org.elasticsearch.index.mapper.ParseContext; -import org.elasticsearch.index.mapper.SourceValueFetcher; import org.elasticsearch.index.mapper.TextSearchInfo; import org.elasticsearch.index.mapper.ValueFetcher; import org.elasticsearch.index.query.QueryShardContext; @@ -116,7 +116,7 @@ public class DenseVectorFieldMapper extends ParametrizedFieldMapper { if (format != null) { throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats."); } - return new SourceValueFetcher(name(), mapperService, true) { + return new ArraySourceValueFetcher(name(), mapperService) { @Override protected Object parseSourceValue(Object value) { return value; diff --git a/x-pack/plugin/vectors/src/test/java/org/elasticsearch/xpack/vectors/mapper/DenseVectorFieldTypeTests.java b/x-pack/plugin/vectors/src/test/java/org/elasticsearch/xpack/vectors/mapper/DenseVectorFieldTypeTests.java index ef202725111..8a247e0cdf1 100644 --- a/x-pack/plugin/vectors/src/test/java/org/elasticsearch/xpack/vectors/mapper/DenseVectorFieldTypeTests.java +++ b/x-pack/plugin/vectors/src/test/java/org/elasticsearch/xpack/vectors/mapper/DenseVectorFieldTypeTests.java @@ -8,7 +8,9 @@ package org.elasticsearch.xpack.vectors.mapper; import org.elasticsearch.index.mapper.FieldTypeTestCase; +import java.io.IOException; import java.util.Collections; +import java.util.List; public class DenseVectorFieldTypeTests extends FieldTypeTestCase { @@ -33,4 +35,10 @@ public class DenseVectorFieldTypeTests extends FieldTypeTestCase { DenseVectorFieldMapper.DenseVectorFieldType ft = new DenseVectorFieldMapper.DenseVectorFieldType("f", 1, Collections.emptyMap()); expectThrows(UnsupportedOperationException.class, () -> ft.docValueFormat(null, null)); } + + public void testFetchSourceValue() throws IOException { + DenseVectorFieldMapper.DenseVectorFieldType ft = new DenseVectorFieldMapper.DenseVectorFieldType("f", 5, Collections.emptyMap()); + List vector = org.elasticsearch.common.collect.List.of(0.0, 1.0, 2.0, 3.0, 4.0); + assertEquals(vector, fetchSourceValue(ft, vector)); + } } diff --git a/x-pack/plugin/wildcard/src/main/java/org/elasticsearch/xpack/wildcard/mapper/WildcardFieldMapper.java b/x-pack/plugin/wildcard/src/main/java/org/elasticsearch/xpack/wildcard/mapper/WildcardFieldMapper.java index 944f44c5910..d93c2f7438c 100644 --- a/x-pack/plugin/wildcard/src/main/java/org/elasticsearch/xpack/wildcard/mapper/WildcardFieldMapper.java +++ b/x-pack/plugin/wildcard/src/main/java/org/elasticsearch/xpack/wildcard/mapper/WildcardFieldMapper.java @@ -982,7 +982,7 @@ public class WildcardFieldMapper extends FieldMapper { throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats."); } - return new SourceValueFetcher(name(), mapperService, false, nullValue) { + return new SourceValueFetcher(name(), mapperService, nullValue) { @Override protected String parseSourceValue(Object value) { String keywordValue = value.toString();