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 705d3efd46321..818da84e5b1f3 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 @@ -187,7 +187,7 @@ public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searc if (format != null) { throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats."); } - return new SourceValueFetcher(name(), mapperService, parsesArrayValue()) { + return new SourceValueFetcher(name(), mapperService, searchLookup.source(), parsesArrayValue()) { @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 bf265e65c9f2e..82aa01e6dc345 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 @@ -166,7 +166,7 @@ public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searc if (format != null) { throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats."); } - return new SourceValueFetcher(name(), mapperService, parsesArrayValue()) { + return new SourceValueFetcher(name(), mapperService, searchLookup.source(), parsesArrayValue()) { @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 664a3a9052501..857a4b1c3db6e 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 @@ -401,7 +401,7 @@ public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searc if (format != null) { throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats."); } - return new SourceValueFetcher(name(), mapperService, parsesArrayValue()) { + return new SourceValueFetcher(name(), mapperService, searchLookup.source(), parsesArrayValue()) { @Override protected Double parseSourceValue(Object value) { double doubleValue; diff --git a/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/TokenCountFieldMapper.java b/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/TokenCountFieldMapper.java index 087b828cdb232..d2e737028bd28 100644 --- a/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/TokenCountFieldMapper.java +++ b/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/TokenCountFieldMapper.java @@ -165,7 +165,7 @@ public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searc throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats."); } - return new SourceValueFetcher(name(), mapperService, parsesArrayValue(), nullValue) { + return new SourceValueFetcher(name(), mapperService, searchLookup.source(), parsesArrayValue(), nullValue) { @Override protected String parseSourceValue(Object value) { return value.toString(); 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 2fb5d37a30957..cae6bde69f65d 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 @@ -356,7 +356,7 @@ public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searc if (format != null) { throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats."); } - return new SourceValueFetcher(name(), mapperService, parsesArrayValue()) { + return new SourceValueFetcher(name(), mapperService, searchLookup.source(), parsesArrayValue()) { @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 e3c514e8bf7a8..7ed108dacda76 100644 --- a/modules/percolator/src/main/java/org/elasticsearch/percolator/PercolatorFieldMapper.java +++ b/modules/percolator/src/main/java/org/elasticsearch/percolator/PercolatorFieldMapper.java @@ -371,7 +371,7 @@ public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searc if (format != null) { throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats."); } - return new SourceValueFetcher(name(), mapperService, parsesArrayValue()) { + return new SourceValueFetcher(name(), mapperService, searchLookup.source(), parsesArrayValue()) { @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 2e0b67643837b..9ccf4e793d7f8 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 @@ -740,7 +740,7 @@ public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searc throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats."); } - return new SourceValueFetcher(name(), mapperService, parsesArrayValue(), nullValue) { + return new SourceValueFetcher(name(), mapperService, searchLookup.source(), parsesArrayValue(), nullValue) { @Override protected String parseSourceValue(Object value) { String keywordValue = value.toString(); diff --git a/plugins/mapper-annotated-text/src/main/java/org/elasticsearch/index/mapper/annotatedtext/AnnotatedTextFieldMapper.java b/plugins/mapper-annotated-text/src/main/java/org/elasticsearch/index/mapper/annotatedtext/AnnotatedTextFieldMapper.java index 4bc255581e850..4dc1da8a5aea3 100644 --- a/plugins/mapper-annotated-text/src/main/java/org/elasticsearch/index/mapper/annotatedtext/AnnotatedTextFieldMapper.java +++ b/plugins/mapper-annotated-text/src/main/java/org/elasticsearch/index/mapper/annotatedtext/AnnotatedTextFieldMapper.java @@ -594,7 +594,7 @@ public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searc if (format != null) { throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats."); } - return new SourceValueFetcher(name(), mapperService, parsesArrayValue()) { + return new SourceValueFetcher(name(), mapperService, searchLookup.source(), parsesArrayValue()) { @Override protected Object parseSourceValue(Object value) { return 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 614df262eba62..786aef5b166ea 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 @@ -157,7 +157,7 @@ public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searc if (format != null) { throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats."); } - return new SourceValueFetcher(name(), mapperService, parsesArrayValue()) { + return new SourceValueFetcher(name(), mapperService, searchLookup.source(), parsesArrayValue()) { @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 3459e7eee8492..b975dc84efe73 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/AbstractGeometryFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/AbstractGeometryFieldMapper.java @@ -192,7 +192,7 @@ public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searc Parser geometryParser = mappedFieldType.geometryParser(); Function valueParser = value -> geometryParser.parseAndFormatObject(value, this, geoFormat); - return new SourceValueFetcher(name(), mapperService, parsesArrayValue()) { + return new SourceValueFetcher(name(), mapperService, searchLookup.source(), parsesArrayValue()) { @Override protected Object parseSourceValue(Object value) { return valueParser.apply(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 1a98b2ea69883..b8a49eacf177e 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/BinaryFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/BinaryFieldMapper.java @@ -196,7 +196,7 @@ public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searc if (format != null) { throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats."); } - return new SourceValueFetcher(name(), mapperService, parsesArrayValue()) { + return new SourceValueFetcher(name(), mapperService, searchLookup.source(), parsesArrayValue()) { @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 e87c5bd0296e7..5d7dc8f294d4a 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/BooleanFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/BooleanFieldMapper.java @@ -258,7 +258,7 @@ public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searc throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats."); } - return new SourceValueFetcher(name(), mapperService, parsesArrayValue(), nullValue) { + return new SourceValueFetcher(name(), mapperService, searchLookup.source(), parsesArrayValue(), 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 7a8c7b6529d20..5b89c4b281121 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/CompletionFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/CompletionFieldMapper.java @@ -546,7 +546,7 @@ public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searc throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats."); } - return new SourceValueFetcher(name(), mapperService, parsesArrayValue()) { + return new SourceValueFetcher(name(), mapperService, searchLookup.source(), parsesArrayValue()) { @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 ffa8335dae125..a1d472dd6ec6b 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java @@ -612,7 +612,7 @@ public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searc ? DateFormatter.forPattern(format).withLocale(defaultFormatter.locale()) : defaultFormatter; - return new SourceValueFetcher(name(), mapperService, parsesArrayValue(), nullValueAsString) { + return new SourceValueFetcher(name(), mapperService, searchLookup.source(), parsesArrayValue(), nullValueAsString) { @Override public String parseSourceValue(Object value) { String date = value.toString(); diff --git a/server/src/main/java/org/elasticsearch/index/mapper/DocValueFetcher.java b/server/src/main/java/org/elasticsearch/index/mapper/DocValueFetcher.java index c8ca9037ff20c..893518cb63096 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/DocValueFetcher.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/DocValueFetcher.java @@ -22,7 +22,6 @@ import org.apache.lucene.index.LeafReaderContext; import org.elasticsearch.index.fielddata.IndexFieldData; import org.elasticsearch.search.DocValueFormat; -import org.elasticsearch.search.lookup.SourceLookup; import java.io.IOException; import java.util.ArrayList; @@ -46,8 +45,8 @@ public void setNextReader(LeafReaderContext context) { } @Override - public List fetchValues(SourceLookup lookup) throws IOException { - if (false == leaf.advanceExact(lookup.docId())) { + public List fetchValues(int docId) throws IOException { + if (false == leaf.advanceExact(docId)) { return List.of(); } List result = new ArrayList(leaf.docValueCount()); 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 68d742961a7fa..2b22881406f72 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/IpFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/IpFieldMapper.java @@ -408,7 +408,7 @@ public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searc if (format != null) { throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats."); } - return new SourceValueFetcher(name(), mapperService, parsesArrayValue(), nullValue) { + return new SourceValueFetcher(name(), mapperService, searchLookup.source(), parsesArrayValue(), 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 b4614bf043639..19549ff840215 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/KeywordFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/KeywordFieldMapper.java @@ -398,7 +398,7 @@ public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searc throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats."); } - return new SourceValueFetcher(name(), mapperService, parsesArrayValue(), nullValue) { + return new SourceValueFetcher(name(), mapperService, searchLookup.source(), parsesArrayValue(), 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 9448266a3d540..09cd9e1507329 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/NumberFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/NumberFieldMapper.java @@ -1094,7 +1094,7 @@ public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searc throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats."); } - return new SourceValueFetcher(name(), mapperService, parsesArrayValue(), nullValue) { + return new SourceValueFetcher(name(), mapperService, searchLookup.source(), parsesArrayValue(), 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 85c3cdb39ad18..ff71f385ad54a 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/RangeFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/RangeFieldMapper.java @@ -366,7 +366,7 @@ public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searc ? DateFormatter.forPattern(format).withLocale(defaultFormatter.locale()) : defaultFormatter; - return new SourceValueFetcher(name(), mapperService, parsesArrayValue()) { + return new SourceValueFetcher(name(), mapperService, searchLookup.source(), parsesArrayValue()) { @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 1f307a7392e4d..9e2fd26be6318 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/SourceValueFetcher.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/SourceValueFetcher.java @@ -35,11 +35,12 @@ */ public abstract class SourceValueFetcher implements ValueFetcher { private final Set sourcePaths; + private final SourceLookup lookup; 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, SourceLookup lookup, boolean parsesArrayValue) { + this(fieldName, mapperService, lookup, parsesArrayValue, null); } /** @@ -47,14 +48,25 @@ public SourceValueFetcher(String fieldName, MapperService mapperService, boolean * @param parsesArrayValue Whether the fetcher handles array values during document parsing. * @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, + SourceLookup lookup, + boolean parsesArrayValue, + Object nullValue + ) { this.sourcePaths = mapperService.sourcePath(fieldName); + this.lookup = lookup; this.nullValue = nullValue; this.parsesArrayValue = parsesArrayValue; } @Override - public List fetchValues(SourceLookup lookup) { + public List fetchValues(int docId) { + /* + * Pulls the values from the source, parses them and then them + * using parseSourceValue. + */ List values = new ArrayList<>(); for (String path : sourcePaths) { Object sourceValue = lookup.extractValue(path, nullValue); 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 1448e5c60b860..d6a74f0beaa21 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java @@ -841,7 +841,7 @@ public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searc if (format != null) { throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats."); } - return new SourceValueFetcher(name(), mapperService, parsesArrayValue()) { + return new SourceValueFetcher(name(), mapperService, searchLookup.source(), parsesArrayValue()) { @Override protected Object parseSourceValue(Object value) { return value.toString(); diff --git a/server/src/main/java/org/elasticsearch/index/mapper/ValueFetcher.java b/server/src/main/java/org/elasticsearch/index/mapper/ValueFetcher.java index 7f8a5b6149613..0217dc12453ff 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/ValueFetcher.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/ValueFetcher.java @@ -21,7 +21,6 @@ import org.apache.lucene.index.LeafReaderContext; import org.elasticsearch.search.fetch.subphase.FetchFieldsPhase; -import org.elasticsearch.search.lookup.SourceLookup; import java.io.IOException; import java.util.List; @@ -32,19 +31,16 @@ */ public interface ValueFetcher { /** - * Given access to a document's _source, return this field's values. - * - * In addition to pulling out the values, they will be parsed into a standard form. - * For example numeric field mappers make sure to parse the source value into a number - * of the right type. - * + * Fetch this field's values, converting them into a "standard form" and applying + * any formats configured when the {@linkplain ValueFetcher} was built. + *

* Note that for array values, the order in which values are returned is undefined and * should not be relied on. * - * @param lookup a lookup structure over the document's source. + * @param docId the document's id. * @return a list a standardized field values. */ - List fetchValues(SourceLookup lookup) throws IOException; + List fetchValues(int docId) throws IOException; /** * Update the leaf reader used to fetch values. diff --git a/server/src/main/java/org/elasticsearch/search/fetch/subphase/FetchDocValuesPhase.java b/server/src/main/java/org/elasticsearch/search/fetch/subphase/FetchDocValuesPhase.java index 8f97092bb49f4..fd7ef31bdadd6 100644 --- a/server/src/main/java/org/elasticsearch/search/fetch/subphase/FetchDocValuesPhase.java +++ b/server/src/main/java/org/elasticsearch/search/fetch/subphase/FetchDocValuesPhase.java @@ -86,7 +86,7 @@ public void process(HitContext hit) throws IOException { // docValues fields will still be document fields, and put under "fields" section of a hit. hit.hit().setDocumentField(f.getKey(), hitField); } - hitField.getValues().addAll(f.getValue().fetchValues(hit.sourceLookup())); + hitField.getValues().addAll(f.getValue().fetchValues(hit.docId())); } } }; diff --git a/server/src/main/java/org/elasticsearch/search/fetch/subphase/FetchFieldsPhase.java b/server/src/main/java/org/elasticsearch/search/fetch/subphase/FetchFieldsPhase.java index 511beded817ca..51cc6ebbdf24c 100644 --- a/server/src/main/java/org/elasticsearch/search/fetch/subphase/FetchFieldsPhase.java +++ b/server/src/main/java/org/elasticsearch/search/fetch/subphase/FetchFieldsPhase.java @@ -27,7 +27,6 @@ import org.elasticsearch.search.fetch.FetchSubPhaseProcessor; import org.elasticsearch.search.internal.SearchContext; import org.elasticsearch.search.lookup.SearchLookup; -import org.elasticsearch.search.lookup.SourceLookup; import java.io.IOException; import java.util.HashSet; @@ -60,10 +59,8 @@ public void setNextReader(LeafReaderContext readerContext) { @Override public void process(HitContext hitContext) throws IOException { SearchHit hit = hitContext.hit(); - SourceLookup sourceLookup = hitContext.sourceLookup(); - Set ignoredFields = getIgnoredFields(hit); - Map documentFields = retriever.retrieve(sourceLookup, ignoredFields); + Map documentFields = retriever.retrieve(hit.docId(), ignoredFields); for (Map.Entry entry : documentFields.entrySet()) { hit.setDocumentField(entry.getKey(), entry.getValue()); } diff --git a/server/src/main/java/org/elasticsearch/search/fetch/subphase/FieldValueRetriever.java b/server/src/main/java/org/elasticsearch/search/fetch/subphase/FieldValueRetriever.java index cea9137ac9784..7be897d2d1651 100644 --- a/server/src/main/java/org/elasticsearch/search/fetch/subphase/FieldValueRetriever.java +++ b/server/src/main/java/org/elasticsearch/search/fetch/subphase/FieldValueRetriever.java @@ -28,7 +28,6 @@ import org.elasticsearch.index.mapper.MappingLookup; import org.elasticsearch.index.mapper.ValueFetcher; import org.elasticsearch.search.lookup.SearchLookup; -import org.elasticsearch.search.lookup.SourceLookup; import java.io.IOException; import java.util.ArrayList; @@ -83,7 +82,7 @@ private FieldValueRetriever(List fieldContexts) { this.fieldContexts = fieldContexts; } - public Map retrieve(SourceLookup sourceLookup, Set ignoredFields) throws IOException { + public Map retrieve(int docId, Set ignoredFields) throws IOException { Map documentFields = new HashMap<>(); for (FieldContext context : fieldContexts) { String field = context.fieldName; @@ -92,7 +91,7 @@ public Map retrieve(SourceLookup sourceLookup, Set parsedValues = valueFetcher.fetchValues(sourceLookup); + List parsedValues = valueFetcher.fetchValues(docId); if (parsedValues.isEmpty() == false) { documentFields.put(field, new DocumentField(field, parsedValues)); 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 a22164a08960c..4b59cc0a5c517 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/ExternalMapper.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/ExternalMapper.java @@ -203,7 +203,7 @@ protected void parseCreateField(ParseContext context) throws IOException { @Override public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searchLookup, String format) { - return new SourceValueFetcher(name(), mapperService, parsesArrayValue()) { + return new SourceValueFetcher(name(), mapperService, searchLookup.source(), parsesArrayValue()) { @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 e7002668c5466..49ded7f17e701 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/FakeStringFieldMapper.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/FakeStringFieldMapper.java @@ -136,7 +136,7 @@ protected void parseCreateField(ParseContext context) throws IOException { @Override public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searchLookup, String format) { - return new SourceValueFetcher(name(), mapperService, parsesArrayValue()) { + return new SourceValueFetcher(name(), mapperService, searchLookup.source(), parsesArrayValue()) { @Override protected String parseSourceValue(Object value) { return value.toString(); diff --git a/server/src/test/java/org/elasticsearch/search/fetch/subphase/FieldValueRetrieverTests.java b/server/src/test/java/org/elasticsearch/search/fetch/subphase/FieldValueRetrieverTests.java index e73b39bfa9a04..24288f08b5bea 100644 --- a/server/src/test/java/org/elasticsearch/search/fetch/subphase/FieldValueRetrieverTests.java +++ b/server/src/test/java/org/elasticsearch/search/fetch/subphase/FieldValueRetrieverTests.java @@ -26,7 +26,7 @@ import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.index.IndexService; import org.elasticsearch.index.mapper.MapperService; -import org.elasticsearch.search.lookup.SourceLookup; +import org.elasticsearch.search.lookup.SearchLookup; import org.elasticsearch.test.ESSingleNodeTestCase; import java.io.IOException; @@ -370,11 +370,11 @@ private Map retrieveFields(MapperService mapperService, X private Map retrieveFields(MapperService mapperService, XContentBuilder source, List fields) throws IOException { - SourceLookup sourceLookup = new SourceLookup(); - sourceLookup.setSource(BytesReference.bytes(source)); + SearchLookup lookup = new SearchLookup(mapperService, null); + lookup.source().setSource(BytesReference.bytes(source)); - FieldValueRetriever fetchFieldsLookup = FieldValueRetriever.create(mapperService, null, fields); - return fetchFieldsLookup.retrieve(sourceLookup, Set.of()); + FieldValueRetriever fetchFieldsLookup = FieldValueRetriever.create(mapperService, lookup, fields); + return fetchFieldsLookup.retrieve(0, Set.of()); } public MapperService createMapperService() throws IOException { diff --git a/test/framework/src/main/java/org/elasticsearch/index/mapper/FieldMapperTestCase.java b/test/framework/src/main/java/org/elasticsearch/index/mapper/FieldMapperTestCase.java index 52a3ccb955b58..50665527adc01 100644 --- a/test/framework/src/main/java/org/elasticsearch/index/mapper/FieldMapperTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/index/mapper/FieldMapperTestCase.java @@ -32,7 +32,7 @@ import org.elasticsearch.index.IndexService; import org.elasticsearch.index.analysis.AnalyzerScope; import org.elasticsearch.index.analysis.NamedAnalyzer; -import org.elasticsearch.search.lookup.SourceLookup; +import org.elasticsearch.search.lookup.SearchLookup; import org.elasticsearch.test.ESSingleNodeTestCase; import java.io.IOException; @@ -265,10 +265,12 @@ public static List fetchSourceValue(FieldMapper mapper, Object sourceValue, S MapperService mapperService = mock(MapperService.class); when(mapperService.sourcePath(field)).thenReturn(Set.of(field)); - ValueFetcher fetcher = mapper.valueFetcher(mapperService, null, format); - SourceLookup lookup = new SourceLookup(); - lookup.setSource(Collections.singletonMap(field, sourceValue)); - return fetcher.fetchValues(lookup); + SearchLookup lookup = new SearchLookup(mapperService, (ft, l) -> { + throw new UnsupportedOperationException(); + }); + ValueFetcher fetcher = mapper.valueFetcher(mapperService, lookup, format); + lookup.source().setSource(Collections.singletonMap(field, sourceValue)); + return fetcher.fetchValues(0); } } diff --git a/test/framework/src/main/java/org/elasticsearch/index/mapper/MapperTestCase.java b/test/framework/src/main/java/org/elasticsearch/index/mapper/MapperTestCase.java index 734880c2ba045..62c9d6a6629ef 100644 --- a/test/framework/src/main/java/org/elasticsearch/index/mapper/MapperTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/index/mapper/MapperTestCase.java @@ -33,7 +33,6 @@ import org.elasticsearch.indices.breaker.NoneCircuitBreakerService; import org.elasticsearch.search.DocValueFormat; import org.elasticsearch.search.lookup.SearchLookup; -import org.elasticsearch.search.lookup.SourceLookup; import java.io.IOException; import java.util.Collections; @@ -142,10 +141,12 @@ public static List fetchSourceValue(FieldMapper mapper, Object sourceValue, S MapperService mapperService = mock(MapperService.class); when(mapperService.sourcePath(field)).thenReturn(Set.of(field)); - ValueFetcher fetcher = mapper.valueFetcher(mapperService, null, format); - SourceLookup lookup = new SourceLookup(); - lookup.setSource(Collections.singletonMap(field, sourceValue)); - return fetcher.fetchValues(lookup); + SearchLookup lookup = new SearchLookup(mapperService, (ft, l) -> { + throw new UnsupportedOperationException(); + }); + ValueFetcher fetcher = mapper.valueFetcher(mapperService, lookup, format); + lookup.source().setSource(Collections.singletonMap(field, sourceValue)); + return fetcher.fetchValues(0); } /** @@ -165,9 +166,8 @@ protected final List fetchFromDocValues(MapperService mapperService, MappedFi ValueFetcher valueFetcher = new DocValueFetcher(format, lookup.doc().getForField(ft)); IndexSearcher searcher = newSearcher(iw); LeafReaderContext context = searcher.getIndexReader().leaves().get(0); - lookup.source().setSegmentAndDocument(context, 0); valueFetcher.setNextReader(context); - result.set(valueFetcher.fetchValues(lookup.source())); + result.set(valueFetcher.fetchValues(0)); }); return result.get(); } 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 46c4f4a6584ef..84455aa81637d 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 @@ -172,7 +172,7 @@ public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searc if (format != null) { throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats."); } - return new SourceValueFetcher(name(), mapperService, parsesArrayValue()) { + return new SourceValueFetcher(name(), mapperService, searchLookup.source(), parsesArrayValue()) { @Override protected Object parseSourceValue(Object value) { return value; diff --git a/x-pack/plugin/mapper-constant-keyword/src/internalClusterTest/java/org/elasticsearch/xpack/constantkeyword/mapper/ConstantKeywordFieldMapperTests.java b/x-pack/plugin/mapper-constant-keyword/src/internalClusterTest/java/org/elasticsearch/xpack/constantkeyword/mapper/ConstantKeywordFieldMapperTests.java index 9cbf209ecb078..99c9624ebdeaf 100644 --- a/x-pack/plugin/mapper-constant-keyword/src/internalClusterTest/java/org/elasticsearch/xpack/constantkeyword/mapper/ConstantKeywordFieldMapperTests.java +++ b/x-pack/plugin/mapper-constant-keyword/src/internalClusterTest/java/org/elasticsearch/xpack/constantkeyword/mapper/ConstantKeywordFieldMapperTests.java @@ -22,13 +22,11 @@ import org.elasticsearch.index.mapper.SourceToParse; import org.elasticsearch.index.mapper.ValueFetcher; import org.elasticsearch.plugins.Plugin; -import org.elasticsearch.search.lookup.SourceLookup; import org.elasticsearch.xpack.constantkeyword.ConstantKeywordMapperPlugin; import org.junit.Before; import java.io.IOException; import java.util.Collection; -import java.util.Collections; import java.util.List; import java.util.Set; @@ -115,18 +113,12 @@ public void testFetchValue() throws Exception { FieldMapper fieldMapper = (FieldMapper) mapperService.documentMapper().mappers().getMapper("field"); ValueFetcher fetcher = fieldMapper.valueFetcher(mapperService, null, null); - SourceLookup missingValueLookup = new SourceLookup(); - SourceLookup nullValueLookup = new SourceLookup(); - nullValueLookup.setSource(Collections.singletonMap("field", null)); - - assertTrue(fetcher.fetchValues(missingValueLookup).isEmpty()); - assertTrue(fetcher.fetchValues(nullValueLookup).isEmpty()); + assertTrue(fetcher.fetchValues(randomInt()).isEmpty()); merge(mapperService, fieldMapping(b -> b.field("type", "constant_keyword").field("value", "foo"))); fieldMapper = (FieldMapper) mapperService.documentMapper().mappers().getMapper("field"); fetcher = fieldMapper.valueFetcher(mapperService, null, null); - assertEquals(List.of("foo"), fetcher.fetchValues(missingValueLookup)); - assertEquals(List.of("foo"), fetcher.fetchValues(nullValueLookup)); + assertEquals(List.of("foo"), fetcher.fetchValues(randomInt())); } } 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 50873db863870..fc8c36c0cc828 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 @@ -568,7 +568,7 @@ public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searc if (format != null) { throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats."); } - return new SourceValueFetcher(name(), mapperService, parsesArrayValue(), nullValue) { + return new SourceValueFetcher(name(), mapperService, searchLookup.source(), parsesArrayValue(), nullValue) { @Override protected Object parseSourceValue(Object value) { return value; 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 abaf41a1f6b77..9ef2a1cb67489 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 @@ -215,7 +215,7 @@ public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searc if (format != null) { throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats."); } - return new SourceValueFetcher(name(), mapperService, parsesArrayValue()) { + return new SourceValueFetcher(name(), mapperService, searchLookup.source(), parsesArrayValue()) { @Override protected Object parseSourceValue(Object value) { return value; diff --git a/x-pack/plugin/vectors/src/main/java/org/elasticsearch/xpack/vectors/mapper/SparseVectorFieldMapper.java b/x-pack/plugin/vectors/src/main/java/org/elasticsearch/xpack/vectors/mapper/SparseVectorFieldMapper.java index 143ffac1bbd45..571429f1aefaa 100644 --- a/x-pack/plugin/vectors/src/main/java/org/elasticsearch/xpack/vectors/mapper/SparseVectorFieldMapper.java +++ b/x-pack/plugin/vectors/src/main/java/org/elasticsearch/xpack/vectors/mapper/SparseVectorFieldMapper.java @@ -151,7 +151,7 @@ public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searc if (format != null) { throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats."); } - return new SourceValueFetcher(name(), mapperService, parsesArrayValue()) { + return new SourceValueFetcher(name(), mapperService, searchLookup.source(), parsesArrayValue()) { @Override protected Object parseSourceValue(Object value) { return value; 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 f147cf9ceb1f5..b8a40b76c94d8 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 @@ -948,7 +948,7 @@ public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searc throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats."); } - return new SourceValueFetcher(name(), mapperService, parsesArrayValue(), nullValue) { + return new SourceValueFetcher(name(), mapperService, searchLookup.source(), parsesArrayValue(), nullValue) { @Override protected String parseSourceValue(Object value) { String keywordValue = value.toString();