Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName, S
}

@Override
public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searchLookup, String format) {
public ValueFetcher valueFetcher(QueryShardContext context, SearchLookup searchLookup, String format) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're passing QueryShardContext I think that means we can avoid passing SearchLookup here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see my comment above, I don't think so, because we need to pass through the fetch lookup that is created in FetchContext?

if (format != null) {
throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats.");
}
return new SourceValueFetcher(name(), mapperService) {
return new SourceValueFetcher(name(), context) {
@Override
protected Float parseSourceValue(Object value) {
return objectToFloat(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public String typeName() {
}

@Override
public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searchLookup, String format) {
public ValueFetcher valueFetcher(QueryShardContext context, SearchLookup searchLookup, String format) {
throw new UnsupportedOperationException("Cannot fetch values for internal field [" + typeName() + "].");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName, S
}

@Override
public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searchLookup, String format) {
return SourceValueFetcher.identity(name(), mapperService, format);
public ValueFetcher valueFetcher(QueryShardContext context, SearchLookup searchLookup, String format) {
return SourceValueFetcher.identity(name(), context, format);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,11 @@ public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName, S
}

@Override
public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searchLookup, String format) {
public ValueFetcher valueFetcher(QueryShardContext context, SearchLookup searchLookup, String format) {
if (format != null) {
throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats.");
}
return new SourceValueFetcher(name(), mapperService) {
return new SourceValueFetcher(name(), context) {
@Override
protected Double parseSourceValue(Object value) {
double doubleValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ private ShingleFieldType shingleFieldForPositions(int positions) {
}

@Override
public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searchLookup, String format) {
return SourceValueFetcher.toString(name(), mapperService, format);
public ValueFetcher valueFetcher(QueryShardContext context, SearchLookup searchLookup, String format) {
return SourceValueFetcher.toString(name(), context, format);
}

@Override
Expand Down Expand Up @@ -375,10 +375,10 @@ public Query prefixQuery(String value, MultiTermQuery.RewriteMethod method, bool
}

@Override
public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searchLookup, String format) {
public ValueFetcher valueFetcher(QueryShardContext context, SearchLookup searchLookup, String format) {
// Because this internal field is modelled as a multi-field, SourceValueFetcher will look up its
// parent field in _source. So we don't need to use the parent field name here.
return SourceValueFetcher.toString(name(), mapperService, format);
return SourceValueFetcher.toString(name(), context, format);
}

@Override
Expand Down Expand Up @@ -487,10 +487,10 @@ void setPrefixFieldType(PrefixFieldType prefixFieldType) {
}

@Override
public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searchLookup, String format) {
public ValueFetcher valueFetcher(QueryShardContext context, SearchLookup searchLookup, String format) {
// Because this internal field is modelled as a multi-field, SourceValueFetcher will look up its
// parent field in _source. So we don't need to use the parent field name here.
return SourceValueFetcher.toString(name(), mapperService, format);
return SourceValueFetcher.toString(name(), context, format);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute;
import org.elasticsearch.index.analysis.NamedAnalyzer;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.search.lookup.SearchLookup;

import java.io.IOException;
Expand Down Expand Up @@ -92,7 +93,7 @@ static class TokenCountFieldType extends NumberFieldMapper.NumberFieldType {
}

@Override
public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searchLookup, String format) {
public ValueFetcher valueFetcher(QueryShardContext context, SearchLookup searchLookup, String format) {
if (hasDocValues() == false) {
return lookup -> List.of();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import org.apache.lucene.search.Query;
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.mapper.MetadataFieldMapper;
import org.elasticsearch.index.mapper.ParseContext;
import org.elasticsearch.index.mapper.StringFieldType;
Expand Down Expand Up @@ -66,7 +65,7 @@ public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName, S
}

@Override
public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searchLookup, String format) {
public ValueFetcher valueFetcher(QueryShardContext context, SearchLookup searchLookup, String format) {
throw new UnsupportedOperationException("Cannot fetch values for metadata field [" + NAME + "].");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.plain.SortedSetOrdinalsIndexFieldData;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.mapper.ParseContext;
import org.elasticsearch.index.mapper.StringFieldType;
import org.elasticsearch.index.mapper.TextSearchInfo;
import org.elasticsearch.index.mapper.ValueFetcher;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
import org.elasticsearch.search.lookup.SearchLookup;

Expand Down Expand Up @@ -76,7 +76,7 @@ public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName, S
}

@Override
public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searchLookup, String format) {
public ValueFetcher valueFetcher(QueryShardContext context, SearchLookup searchLookup, String format) {
throw new UnsupportedOperationException("Cannot fetch values for internal field [" + typeName() + "].");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.Mapper;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.mapper.ParseContext;
import org.elasticsearch.index.mapper.SourceValueFetcher;
import org.elasticsearch.index.mapper.StringFieldType;
import org.elasticsearch.index.mapper.TextSearchInfo;
import org.elasticsearch.index.mapper.ValueFetcher;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
import org.elasticsearch.search.lookup.SearchLookup;

Expand Down Expand Up @@ -163,8 +163,8 @@ public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName, S
}

@Override
public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searchLookup, String format) {
return SourceValueFetcher.identity(name(), mapperService, format);
public ValueFetcher valueFetcher(QueryShardContext context, SearchLookup searchLookup, String format) {
return SourceValueFetcher.identity(name(), context, format);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.Mapper;
import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.mapper.NumberFieldMapper;
import org.elasticsearch.index.mapper.ParseContext;
import org.elasticsearch.index.mapper.RangeFieldMapper;
Expand Down Expand Up @@ -217,8 +216,8 @@ public Query termQuery(Object value, QueryShardContext context) {
}

@Override
public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searchLookup, String format) {
return SourceValueFetcher.identity(name(), mapperService, format);
public ValueFetcher valueFetcher(QueryShardContext context, SearchLookup searchLookup, String format) {
return SourceValueFetcher.identity(name(), context, format);
}

Query percolateQuery(String name, PercolateQuery.QueryStore queryStore, List<BytesReference> documents,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ public String typeName() {
}

@Override
public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searchLookup, String format) {
public ValueFetcher valueFetcher(QueryShardContext context, SearchLookup searchLookup, String format) {
if (format != null) {
throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats.");
}

return new SourceValueFetcher(name(), mapperService, nullValue) {
return new SourceValueFetcher(name(), context, nullValue) {
@Override
protected String parseSourceValue(Object value) {
String keywordValue = value.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.elasticsearch.index.fielddata.plain.SortedNumericIndexFieldData;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.mapper.ParseContext;
import org.elasticsearch.index.mapper.SourceValueFetcher;
import org.elasticsearch.index.mapper.TextSearchInfo;
Expand Down Expand Up @@ -104,8 +103,8 @@ public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName, S
}

@Override
public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searchLookup, String format) {
return SourceValueFetcher.toString(name(), mapperService, format);
public ValueFetcher valueFetcher(QueryShardContext context, SearchLookup searchLookup, String format) {
return SourceValueFetcher.toString(name(), context, format);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,19 @@ public final Query termQuery(Object value, QueryShardContext context) {
}

@Override
public final ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searchLookup, String format) {
public final ValueFetcher valueFetcher(QueryShardContext context, SearchLookup searchLookup, String format) {
String geoFormat = format != null ? format : GeoJsonGeometryFormat.NAME;

Function<Object, Object> valueParser = value -> geometryParser.parseAndFormatObject(value, geoFormat);
if (parsesArrayValue) {
return new ArraySourceValueFetcher(name(), mapperService) {
return new ArraySourceValueFetcher(name(), context) {
@Override
protected Object parseSourceValue(Object value) {
return valueParser.apply(value);
}
};
} else {
return new SourceValueFetcher(name(), mapperService) {
return new SourceValueFetcher(name(), context) {
@Override
protected Object parseSourceValue(Object value) {
return valueParser.apply(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.elasticsearch.index.mapper;

import org.elasticsearch.common.Nullable;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.search.lookup.SourceLookup;

import java.util.ArrayList;
Expand All @@ -38,17 +39,17 @@ public abstract class ArraySourceValueFetcher implements ValueFetcher {
private final Set<String> sourcePaths;
private final @Nullable Object nullValue;

public ArraySourceValueFetcher(String fieldName, MapperService mapperService) {
this(fieldName, mapperService, null);
public ArraySourceValueFetcher(String fieldName, QueryShardContext context) {
this(fieldName, context, null);
}

/**
* @param fieldName The name of the field.
* @param mapperService A mapper service.
* @param context The query shard context
* @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);
public ArraySourceValueFetcher(String fieldName, QueryShardContext context, Object nullValue) {
this.sourcePaths = context.sourcePath(fieldName);
this.nullValue = nullValue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ public String typeName() {
}

@Override
public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searchLookup, String format) {
return SourceValueFetcher.identity(name(), mapperService, format);
public ValueFetcher valueFetcher(QueryShardContext context, SearchLookup searchLookup, String format) {
return SourceValueFetcher.identity(name(), context, format);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@ public String typeName() {
}

@Override
public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searchLookup, String format) {
public ValueFetcher valueFetcher(QueryShardContext context, SearchLookup searchLookup, String format) {
if (format != null) {
throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats.");
}

return new SourceValueFetcher(name(), mapperService, nullValue) {
return new SourceValueFetcher(name(), context, nullValue) {
@Override
protected Boolean parseSourceValue(Object value) {
if (value instanceof Boolean) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.elasticsearch.common.xcontent.XContentParser.Token;
import org.elasticsearch.index.analysis.AnalyzerScope;
import org.elasticsearch.index.analysis.NamedAnalyzer;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.search.lookup.SearchLookup;
import org.elasticsearch.search.suggest.completion.CompletionSuggester;
import org.elasticsearch.search.suggest.completion.context.ContextMapping;
Expand Down Expand Up @@ -306,12 +307,12 @@ public String typeName() {
}

@Override
public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searchLookup, String format) {
public ValueFetcher valueFetcher(QueryShardContext context, SearchLookup searchLookup, String format) {
if (format != null) {
throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats.");
}

return new ArraySourceValueFetcher(name(), mapperService) {
return new ArraySourceValueFetcher(name(), context) {
@Override
protected List<?> parseSourceValue(Object value) {
if (value instanceof List) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,13 +319,13 @@ public long parse(String value) {
}

@Override
public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searchLookup, String format) {
public ValueFetcher valueFetcher(QueryShardContext context, SearchLookup searchLookup, String format) {
DateFormatter defaultFormatter = dateTimeFormatter();
DateFormatter formatter = format != null
? DateFormatter.forPattern(format).withLocale(defaultFormatter.locale())
: defaultFormatter;

return new SourceValueFetcher(name(), mapperService, nullValue) {
return new SourceValueFetcher(name(), context, nullValue) {
@Override
public String parseSourceValue(Object value) {
String date = value.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public boolean isEnabled() {
}

@Override
public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup lookup, String format) {
public ValueFetcher valueFetcher(QueryShardContext context, SearchLookup lookup, String format) {
throw new UnsupportedOperationException("Cannot fetch values for internal field [" + name() + "].");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public boolean isSearchable() {
}

@Override
public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup lookup, String format) {
public ValueFetcher valueFetcher(QueryShardContext context, SearchLookup lookup, String format) {
throw new UnsupportedOperationException("Cannot fetch values for internal field [" + name() + "].");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public Query existsQuery(QueryShardContext context) {
}

@Override
public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup lookup, String format) {
public ValueFetcher valueFetcher(QueryShardContext context, SearchLookup lookup, String format) {
throw new UnsupportedOperationException("Cannot fetch values for internal field [" + name() + "].");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName, S
}

@Override
public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searchLookup, String format) {
public ValueFetcher valueFetcher(QueryShardContext context, SearchLookup searchLookup, String format) {
throw new UnsupportedOperationException("Cannot fetch values for internal field [" + name() + "].");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,11 @@ private static InetAddress parse(Object value) {
}

@Override
public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searchLookup, String format) {
public ValueFetcher valueFetcher(QueryShardContext context, SearchLookup searchLookup, String format) {
if (format != null) {
throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats.");
}
return new SourceValueFetcher(name(), mapperService, nullValue) {
return new SourceValueFetcher(name(), context, nullValue) {
@Override
protected Object parseSourceValue(Object value) {
InetAddress address;
Expand Down
Loading