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 @@ -197,11 +197,11 @@ public Query rangeQuery(Object lowerTerm, Object upperTerm, boolean includeLower
@Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName, Supplier<SearchLookup> searchLookup) {
failIfNoDocValues();
return (cache, breakerService, mapperService) -> {
return (cache, breakerService) -> {
final IndexNumericFieldData scaledValues = new SortedNumericIndexFieldData.Builder(
name(),
IndexNumericFieldData.NumericType.LONG
).build(cache, breakerService, mapperService);
).build(cache, breakerService);
return new ScaledFloatIndexFieldData(scaledValues, scalingFactor);
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public void testFieldData() throws IOException {
= new ScaledFloatFieldMapper.ScaledFloatFieldType("scaled_float1", scalingFactor);
IndexNumericFieldData fielddata = (IndexNumericFieldData) f1.fielddataBuilder("index", () -> {
throw new UnsupportedOperationException();
}).build(null, null, null);
}).build(null, null);
assertEquals(fielddata.getNumericType(), IndexNumericFieldData.NumericType.DOUBLE);
LeafNumericFieldData leafFieldData = fielddata.load(reader.leaves().get(0));
SortedNumericDoubleValues values = leafFieldData.getDoubleValues();
Expand All @@ -169,7 +169,7 @@ public void testFieldData() throws IOException {
= new ScaledFloatFieldMapper.ScaledFloatFieldType("scaled_float2", scalingFactor);
fielddata = (IndexNumericFieldData) f2.fielddataBuilder("index", () -> {
throw new UnsupportedOperationException();
}).build(null, null, null);
}).build(null, null);
leafFieldData = fielddata.load(reader.leaves().get(0));
values = leafFieldData.getDoubleValues();
assertTrue(values.advanceExact(0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ public <IFD extends IndexFieldData<?>> IFD getForField(MappedFieldType fieldType
shardContext::lookup);
IndexFieldDataCache cache = new IndexFieldDataCache.None();
CircuitBreakerService circuitBreaker = new NoneCircuitBreakerService();
return (IFD) builder.build(cache, circuitBreaker, shardContext.getMapperService());
return (IFD) builder.build(cache, circuitBreaker);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.util.BigArrays;
import org.elasticsearch.index.fielddata.IndexFieldData.XFieldComparatorSource.Nested;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.indices.breaker.CircuitBreakerService;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.MultiValueMode;
Expand Down Expand Up @@ -246,7 +245,7 @@ public abstract BucketedSort newBucketedSort(BigArrays bigArrays, SortOrder sort

interface Builder {

IndexFieldData<?> build(IndexFieldDataCache cache, CircuitBreakerService breakerService, MapperService mapperService);
IndexFieldData<?> build(IndexFieldDataCache cache, CircuitBreakerService breakerService);
}

interface Global<FD extends LeafFieldData> extends IndexFieldData<FD> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public <IFD extends IndexFieldData<?>> IFD getForField(MappedFieldType fieldType
}
}

return (IFD) builder.build(cache, circuitBreakerService, mapperService);
return (IFD) builder.build(cache, circuitBreakerService);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.elasticsearch.index.fielddata.IndexFieldDataCache;
import org.elasticsearch.index.fielddata.IndexGeoPointFieldData;
import org.elasticsearch.index.fielddata.LeafGeoPointFieldData;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.indices.breaker.CircuitBreakerService;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.MultiValueMode;
Expand Down Expand Up @@ -113,7 +112,7 @@ public Builder(String name, ValuesSourceType valuesSourceType) {
}

@Override
public IndexFieldData<?> build(IndexFieldDataCache cache, CircuitBreakerService breakerService, MapperService mapperService) {
public IndexFieldData<?> build(IndexFieldDataCache cache, CircuitBreakerService breakerService) {
// ignore breaker
return new LatLonPointIndexFieldData(name, valuesSourceType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.elasticsearch.index.fielddata.IndexFieldData.XFieldComparatorSource.Nested;
import org.elasticsearch.index.fielddata.IndexFieldDataCache;
import org.elasticsearch.index.fielddata.fieldcomparator.BytesRefFieldComparatorSource;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.indices.breaker.CircuitBreakerService;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.MultiValueMode;
Expand All @@ -47,7 +46,7 @@ public Builder(String name, ValuesSourceType valuesSourceType) {
}

@Override
public BinaryIndexFieldData build(IndexFieldDataCache cache, CircuitBreakerService breakerService, MapperService mapperService) {
public BinaryIndexFieldData build(IndexFieldDataCache cache, CircuitBreakerService breakerService) {
return new BinaryIndexFieldData(name, valuesSourceType);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.IndexFieldData.XFieldComparatorSource.Nested;
import org.elasticsearch.index.fielddata.IndexFieldDataCache;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.indices.breaker.CircuitBreakerService;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.MultiValueMode;
Expand Down Expand Up @@ -92,7 +91,7 @@ public Builder(String name, ValuesSourceType valuesSourceType) {
}

@Override
public IndexFieldData<?> build(IndexFieldDataCache cache, CircuitBreakerService breakerService, MapperService mapperService) {
public IndexFieldData<?> build(IndexFieldDataCache cache, CircuitBreakerService breakerService) {
// Ignore breaker
return new BytesBinaryIndexFieldData(name, valuesSourceType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,38 +36,34 @@
import org.elasticsearch.index.fielddata.IndexOrdinalsFieldData;
import org.elasticsearch.index.fielddata.LeafOrdinalsFieldData;
import org.elasticsearch.index.fielddata.fieldcomparator.BytesRefFieldComparatorSource;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.indices.breaker.CircuitBreakerService;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.MultiValueMode;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import org.elasticsearch.search.sort.BucketedSort;
import org.elasticsearch.search.sort.SortOrder;

import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.function.Function;

public class ConstantIndexFieldData extends AbstractIndexOrdinalsFieldData {

public static class Builder implements IndexFieldData.Builder {

private final Function<MapperService, String> valueFunction;
private final String constantValue;
private final String name;
private final ValuesSourceType valuesSourceType;

public Builder(Function<MapperService, String> valueFunction, String name, ValuesSourceType valuesSourceType) {
this.valueFunction = valueFunction;
public Builder(String constantValue, String name, ValuesSourceType valuesSourceType) {
this.constantValue = constantValue;
this.name = name;
this.valuesSourceType = valuesSourceType;
}

@Override
public IndexFieldData<?> build(IndexFieldDataCache cache, CircuitBreakerService breakerService, MapperService mapperService) {
return new ConstantIndexFieldData(name, valueFunction.apply(mapperService), valuesSourceType);
public IndexFieldData<?> build(IndexFieldDataCache cache, CircuitBreakerService breakerService) {
return new ConstantIndexFieldData(name, constantValue, valuesSourceType);
}

}

private static class ConstantLeafFieldData extends AbstractLeafOrdinalsFieldData {
Expand Down Expand Up @@ -116,7 +112,7 @@ public int ordValue() {
}

@Override
public boolean advanceExact(int target) throws IOException {
public boolean advanceExact(int target) {
docID = target;
return true;
}
Expand All @@ -126,7 +122,7 @@ public int docID() {
return docID;
}
};
return (SortedSetDocValues) DocValues.singleton(sortedValues);
return DocValues.singleton(sortedValues);
}

@Override
Expand All @@ -148,8 +144,7 @@ public final LeafOrdinalsFieldData load(LeafReaderContext context) {
}

@Override
public LeafOrdinalsFieldData loadDirect(LeafReaderContext context)
throws Exception {
public LeafOrdinalsFieldData loadDirect(LeafReaderContext context) {
return atomicFieldData;
}

Expand All @@ -172,7 +167,7 @@ public IndexOrdinalsFieldData loadGlobal(DirectoryReader indexReader) {
}

@Override
public IndexOrdinalsFieldData loadGlobalDirect(DirectoryReader indexReader) throws Exception {
public IndexOrdinalsFieldData loadGlobalDirect(DirectoryReader indexReader) {
return loadGlobal(indexReader);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import org.elasticsearch.index.fielddata.fieldcomparator.BytesRefFieldComparatorSource;
import org.elasticsearch.index.fielddata.ordinals.Ordinals;
import org.elasticsearch.index.fielddata.ordinals.OrdinalsBuilder;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.indices.breaker.CircuitBreakerService;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.MultiValueMode;
Expand Down Expand Up @@ -77,7 +76,7 @@ public Builder(String name, double minFrequency, double maxFrequency, int minSeg
}

@Override
public IndexOrdinalsFieldData build(IndexFieldDataCache cache, CircuitBreakerService breakerService, MapperService mapperService) {
public IndexOrdinalsFieldData build(IndexFieldDataCache cache, CircuitBreakerService breakerService) {
return new PagedBytesIndexFieldData(name, valuesSourceType, cache, breakerService,
minFrequency, maxFrequency, minSegmentSize);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import org.elasticsearch.index.fielddata.SortedNumericDoubleValues;
import org.elasticsearch.index.fielddata.fieldcomparator.LongValuesComparatorSource;
import org.elasticsearch.index.mapper.DocValueFetcher;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.indices.breaker.CircuitBreakerService;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.MultiValueMode;
Expand Down Expand Up @@ -67,8 +66,7 @@ public Builder(String name, NumericType numericType) {
@Override
public SortedNumericIndexFieldData build(
IndexFieldDataCache cache,
CircuitBreakerService breakerService,
MapperService mapperService
CircuitBreakerService breakerService
) {
return new SortedNumericIndexFieldData(name, numericType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.elasticsearch.index.fielddata.LeafOrdinalsFieldData;
import org.elasticsearch.index.fielddata.ScriptDocValues;
import org.elasticsearch.index.fielddata.fieldcomparator.BytesRefFieldComparatorSource;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.indices.breaker.CircuitBreakerService;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.MultiValueMode;
Expand Down Expand Up @@ -63,8 +62,7 @@ public Builder(String name, Function<SortedSetDocValues, ScriptDocValues<?>> scr
@Override
public SortedSetOrdinalsIndexFieldData build(
IndexFieldDataCache cache,
CircuitBreakerService breakerService,
MapperService mapperService
CircuitBreakerService breakerService
) {
return new SortedSetOrdinalsIndexFieldData(cache, name, valuesSourceType, breakerService, scriptFunction);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,15 @@ public static class Defaults {
}
}

public static final TypeParser PARSER = new FixedTypeParser(c -> new IdFieldMapper());
public static final TypeParser PARSER = new FixedTypeParser(c -> new IdFieldMapper(() -> c.mapperService().isIdFieldDataEnabled()));

static final class IdFieldType extends TermBasedFieldType {

public static final IdFieldType INSTANCE = new IdFieldType();
private final Supplier<Boolean> fieldDataEnabled;

private IdFieldType() {
IdFieldType(Supplier<Boolean> fieldDataEnabled) {
super(NAME, true, true, false, TextSearchInfo.SIMPLE_MATCH_ONLY, Collections.emptyMap());
this.fieldDataEnabled = fieldDataEnabled;
setIndexAnalyzer(Lucene.KEYWORD_ANALYZER);
}

Expand Down Expand Up @@ -148,6 +149,11 @@ public Query termsQuery(List<?> values, QueryShardContext context) {

@Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName, Supplier<SearchLookup> searchLookup) {
if (fieldDataEnabled.get() == false) {
throw new IllegalArgumentException("Fielddata access on the _id field is disallowed, "
+ "you can re-enable it by updating the dynamic cluster setting: "
+ IndicesService.INDICES_ID_FIELD_DATA_ENABLED_SETTING.getKey());
}
final IndexFieldData.Builder fieldDataBuilder = new PagedBytesIndexFieldData.Builder(
name(),
TextFieldMapper.Defaults.FIELDDATA_MIN_FREQUENCY,
Expand All @@ -158,17 +164,11 @@ public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName, S
@Override
public IndexFieldData<?> build(
IndexFieldDataCache cache,
CircuitBreakerService breakerService,
MapperService mapperService
CircuitBreakerService breakerService
) {
if (mapperService.isIdFieldDataEnabled() == false) {
throw new IllegalArgumentException("Fielddata access on the _id field is disallowed, "
+ "you can re-enable it by updating the dynamic cluster setting: "
+ IndicesService.INDICES_ID_FIELD_DATA_ENABLED_SETTING.getKey());
}
deprecationLogger.deprecate("id_field_data", ID_FIELD_DATA_DEPRECATION_MESSAGE);
final IndexFieldData<?> fieldData = fieldDataBuilder.build(cache,
breakerService, mapperService);
breakerService);
return new IndexFieldData<>() {
@Override
public String getFieldName() {
Expand Down Expand Up @@ -256,12 +256,12 @@ public boolean advanceExact(int doc) throws IOException {
};
}

private IdFieldMapper() {
super(new IdFieldType());
private IdFieldMapper(Supplier<Boolean> fieldDataEnabled) {
super(new IdFieldType(fieldDataEnabled));
}

@Override
public void preParse(ParseContext context) throws IOException {
public void preParse(ParseContext context) {
BytesRef id = Uid.encodeId(context.sourceToParse().id());
context.doc().add(new Field(NAME, id, Defaults.FIELD_TYPE));
}
Expand All @@ -270,5 +270,4 @@ public void preParse(ParseContext context) throws IOException {
protected String contentType() {
return CONTENT_TYPE;
}

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

@Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName, Supplier<SearchLookup> searchLookup) {
return new ConstantIndexFieldData.Builder(mapperService -> fullyQualifiedIndexName, name(), CoreValuesSourceType.BYTES);
return new ConstantIndexFieldData.Builder(fullyQualifiedIndexName, name(), CoreValuesSourceType.BYTES);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.elasticsearch.search.lookup.SearchLookup;

import java.util.Collections;
import java.util.function.Function;
import java.util.function.Supplier;

/**
Expand Down Expand Up @@ -65,9 +64,8 @@ public Query existsQuery(QueryShardContext context) {

@Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName, Supplier<SearchLookup> searchLookup) {
Function<MapperService, String> typeFunction = mapperService -> type;
deprecationLogger.deprecate("typefieldtype", TYPES_V7_DEPRECATION_MESSAGE);
return new ConstantIndexFieldData.Builder(typeFunction, name(), CoreValuesSourceType.BYTES);
return new ConstantIndexFieldData.Builder(type, name(), CoreValuesSourceType.BYTES);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public void testGetForFieldRuntimeField() {
@SuppressWarnings("unchecked")
Supplier<SearchLookup> searchLookup = (Supplier<SearchLookup>)invocationOnMock.getArguments()[1];
searchLookupSetOnce.set(searchLookup);
return (IndexFieldData.Builder) (cache, breakerService, mapperService) -> null;
return (IndexFieldData.Builder) (cache, breakerService) -> null;
});
SearchLookup searchLookup = new SearchLookup(null, null);
ifdService.getForField(ft, "qualified", () -> searchLookup);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void testEnableFieldData() throws IOException {
IllegalArgumentException exc = expectThrows(IllegalArgumentException.class,
() -> ft.fielddataBuilder("test", () -> {
throw new UnsupportedOperationException();
}).build(null, null, mapperService));
}).build(null, null));
assertThat(exc.getMessage(), containsString(IndicesService.INDICES_ID_FIELD_DATA_ENABLED_SETTING.getKey()));

client().admin().cluster().prepareUpdateSettings()
Expand All @@ -95,7 +95,7 @@ public void testEnableFieldData() throws IOException {
try {
ft.fielddataBuilder("test", () -> {
throw new UnsupportedOperationException();
}).build(null, null, mapperService);
}).build(null, null);
assertWarnings(ID_FIELD_DATA_DEPRECATION_MESSAGE);
} finally {
// unset cluster setting
Expand Down
Loading