IndexFieldData should hold the ValuesSourceType (#57373) (#57532)

This commit is contained in:
Mark Tozzi 2020-06-02 12:16:53 -04:00 committed by GitHub
parent a2e44a0c76
commit e50f514092
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
83 changed files with 500 additions and 373 deletions

View File

@ -54,7 +54,6 @@ import org.elasticsearch.index.mapper.NumberFieldMapper.Defaults;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.indices.breaker.CircuitBreakerService;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import java.io.IOException;
@ -282,11 +281,6 @@ public class ScaledFloatFieldMapper extends FieldMapper {
};
}
@Override
public ValuesSourceType getValuesSourceType() {
return CoreValuesSourceType.NUMERIC;
}
@Override
public Object valueForDisplay(Object value) {
if (value == null) {
@ -506,6 +500,11 @@ public class ScaledFloatFieldMapper extends FieldMapper {
return scaledFieldData.getFieldName();
}
@Override
public ValuesSourceType getValuesSourceType() {
return scaledFieldData.getValuesSourceType();
}
@Override
public LeafNumericFieldData load(LeafReaderContext context) {
return new ScaledFloatLeafFieldData(scaledFieldData.load(context), scalingFactor);

View File

@ -42,8 +42,7 @@ import java.io.IOException;
import java.util.Map;
import java.util.Objects;
public class ChildrenAggregationBuilder
extends ValuesSourceAggregationBuilder<ChildrenAggregationBuilder> {
public class ChildrenAggregationBuilder extends ValuesSourceAggregationBuilder<ChildrenAggregationBuilder> {
public static final String NAME = "children";

View File

@ -31,7 +31,6 @@ import org.elasticsearch.index.mapper.ParseContext;
import org.elasticsearch.index.mapper.StringFieldType;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import java.io.IOException;
import java.util.List;
@ -97,12 +96,7 @@ public class MetaJoinFieldMapper extends FieldMapper {
@Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
failIfNoDocValues();
return new SortedSetOrdinalsIndexFieldData.Builder();
}
@Override
public ValuesSourceType getValuesSourceType() {
return CoreValuesSourceType.BYTES;
return new SortedSetOrdinalsIndexFieldData.Builder(CoreValuesSourceType.BYTES);
}
@Override

View File

@ -40,7 +40,6 @@ import org.elasticsearch.index.mapper.ParseContext;
import org.elasticsearch.index.mapper.StringFieldType;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import java.io.IOException;
import java.util.Collection;
@ -115,12 +114,7 @@ public final class ParentIdFieldMapper extends FieldMapper {
@Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
failIfNoDocValues();
return new SortedSetOrdinalsIndexFieldData.Builder();
}
@Override
public ValuesSourceType getValuesSourceType() {
return CoreValuesSourceType.BYTES;
return new SortedSetOrdinalsIndexFieldData.Builder(CoreValuesSourceType.BYTES);
}
@Override

View File

@ -45,7 +45,6 @@ import org.elasticsearch.index.mapper.ParseContext;
import org.elasticsearch.index.mapper.StringFieldType;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import java.io.IOException;
import java.util.ArrayList;
@ -233,12 +232,7 @@ public final class ParentJoinFieldMapper extends FieldMapper {
@Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
failIfNoDocValues();
return new SortedSetOrdinalsIndexFieldData.Builder();
}
@Override
public ValuesSourceType getValuesSourceType() {
return CoreValuesSourceType.BYTES;
return new SortedSetOrdinalsIndexFieldData.Builder(CoreValuesSourceType.BYTES);
}
@Override

View File

@ -45,6 +45,7 @@ import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.index.query.TermQueryBuilder;
import org.elasticsearch.mock.orig.Mockito;
import org.elasticsearch.search.SearchModule;
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
import org.elasticsearch.test.ESTestCase;
import java.io.IOException;
@ -94,7 +95,7 @@ public class QueryBuilderStoreTests extends ESTestCase {
when(queryShardContext.getWriteableRegistry()).thenReturn(writableRegistry());
when(queryShardContext.getXContentRegistry()).thenReturn(xContentRegistry());
when(queryShardContext.getForField(fieldMapper.fieldType()))
.thenReturn(new BytesBinaryIndexFieldData(new Index("index", "uuid"), fieldMapper.name()));
.thenReturn(new BytesBinaryIndexFieldData(new Index("index", "uuid"), fieldMapper.name(), CoreValuesSourceType.BYTES));
when(queryShardContext.fieldMapper(Mockito.anyString())).thenAnswer(invocation -> {
final String fieldName = (String) invocation.getArguments()[0];
KeywordFieldMapper.KeywordFieldType ft = new KeywordFieldMapper.KeywordFieldType();

View File

@ -46,7 +46,6 @@ import org.elasticsearch.index.fielddata.plain.SortedSetOrdinalsIndexFieldData;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import java.io.IOException;
import java.time.ZoneId;
@ -127,12 +126,7 @@ public class ICUCollationKeywordFieldMapper extends FieldMapper {
@Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
failIfNoDocValues();
return new SortedSetOrdinalsIndexFieldData.Builder();
}
@Override
public ValuesSourceType getValuesSourceType() {
return CoreValuesSourceType.BYTES;
return new SortedSetOrdinalsIndexFieldData.Builder(CoreValuesSourceType.BYTES);
}
@Override

View File

@ -38,8 +38,6 @@ import org.elasticsearch.index.mapper.ParseContext;
import org.elasticsearch.index.mapper.TypeParsers;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.index.query.QueryShardException;
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import java.io.IOException;
import java.util.List;
@ -125,11 +123,6 @@ public class Murmur3FieldMapper extends FieldMapper {
return new SortedNumericIndexFieldData.Builder(NumericType.LONG);
}
@Override
public ValuesSourceType getValuesSourceType() {
return CoreValuesSourceType.NUMERIC;
}
@Override
public Query existsQuery(QueryShardContext context) {
return new DocValuesFieldExistsQuery(name());

View File

@ -44,6 +44,7 @@ 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.NestedSortBuilder;
import org.elasticsearch.search.sort.SortOrder;
@ -61,6 +62,12 @@ public interface IndexFieldData<FD extends LeafFieldData> extends IndexComponent
*/
String getFieldName();
/**
* The ValuesSourceType of the underlying data. It's possible for fields that use the same IndexFieldData implementation to have
* different ValuesSourceTypes, such as in the case of Longs and Dates.
*/
ValuesSourceType getValuesSourceType();
/**
* Loads the atomic field data for the reader, possibly cached.
*/

View File

@ -21,6 +21,7 @@ package org.elasticsearch.index.fielddata;
import org.elasticsearch.index.Index;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
/**
* Specialization of {@link IndexFieldData} for histograms.
@ -28,10 +29,12 @@ import org.elasticsearch.index.Index;
public abstract class IndexHistogramFieldData implements IndexFieldData<LeafHistogramFieldData> {
protected final Index index;
protected final String fieldName;
protected final ValuesSourceType valuesSourceType;
public IndexHistogramFieldData(Index index, String fieldName) {
public IndexHistogramFieldData(Index index, String fieldName, ValuesSourceType valuesSourceType) {
this.index = index;
this.fieldName = fieldName;
this.valuesSourceType = valuesSourceType;
}
@Override
@ -39,6 +42,11 @@ public abstract class IndexHistogramFieldData implements IndexFieldData<LeafHist
return fieldName;
}
@Override
public ValuesSourceType getValuesSourceType() {
return valuesSourceType;
}
@Override
public final void clear() {
// can't do

View File

@ -34,6 +34,8 @@ import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.MultiValueMode;
import org.elasticsearch.search.sort.BucketedSort;
import org.elasticsearch.search.sort.SortOrder;
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import java.io.IOException;
import java.util.function.LongUnaryOperator;
@ -46,28 +48,33 @@ public abstract class IndexNumericFieldData implements IndexFieldData<LeafNumeri
* The type of number.
*/
public enum NumericType {
BOOLEAN(false, SortField.Type.LONG),
BYTE(false, SortField.Type.LONG),
SHORT(false, SortField.Type.LONG),
INT(false, SortField.Type.LONG),
LONG(false, SortField.Type.LONG),
DATE(false, SortField.Type.LONG),
DATE_NANOSECONDS(false, SortField.Type.LONG),
HALF_FLOAT(true, SortField.Type.LONG),
FLOAT(true, SortField.Type.FLOAT),
DOUBLE(true, SortField.Type.DOUBLE);
BOOLEAN(false, SortField.Type.LONG, CoreValuesSourceType.BOOLEAN),
BYTE(false, SortField.Type.LONG, CoreValuesSourceType.NUMERIC),
SHORT(false, SortField.Type.LONG, CoreValuesSourceType.NUMERIC),
INT(false, SortField.Type.LONG, CoreValuesSourceType.NUMERIC),
LONG(false, SortField.Type.LONG, CoreValuesSourceType.NUMERIC),
DATE(false, SortField.Type.LONG, CoreValuesSourceType.DATE),
DATE_NANOSECONDS(false, SortField.Type.LONG, CoreValuesSourceType.DATE),
HALF_FLOAT(true, SortField.Type.LONG, CoreValuesSourceType.NUMERIC),
FLOAT(true, SortField.Type.FLOAT, CoreValuesSourceType.NUMERIC),
DOUBLE(true, SortField.Type.DOUBLE, CoreValuesSourceType.NUMERIC);
private final boolean floatingPoint;
private final ValuesSourceType valuesSourceType;
private final SortField.Type sortFieldType;
NumericType(boolean floatingPoint, SortField.Type sortFieldType) {
NumericType(boolean floatingPoint, SortField.Type sortFieldType, ValuesSourceType valuesSourceType) {
this.floatingPoint = floatingPoint;
this.sortFieldType = sortFieldType;
this.valuesSourceType = valuesSourceType;
}
public final boolean isFloatingPoint() {
return floatingPoint;
}
public final ValuesSourceType getValuesSourceType() {
return valuesSourceType;
}
}
/**

View File

@ -74,7 +74,7 @@ public enum GlobalOrdinalsBuilder {
new TimeValue(System.nanoTime() - startTimeNS, TimeUnit.NANOSECONDS)
);
}
return new GlobalOrdinalsIndexFieldData(indexSettings, indexFieldData.getFieldName(),
return new GlobalOrdinalsIndexFieldData(indexSettings, indexFieldData.getFieldName(), indexFieldData.getValuesSourceType(),
atomicFD, ordinalMap, memorySizeInBytes, scriptFunction
);
}
@ -109,7 +109,7 @@ public enum GlobalOrdinalsBuilder {
subs[i] = atomicFD[i].getOrdinalsValues();
}
final OrdinalMap ordinalMap = OrdinalMap.build(null, subs, PackedInts.DEFAULT);
return new GlobalOrdinalsIndexFieldData(indexSettings, indexFieldData.getFieldName(),
return new GlobalOrdinalsIndexFieldData(indexSettings, indexFieldData.getFieldName(), indexFieldData.getValuesSourceType(),
atomicFD, ordinalMap, 0, AbstractLeafOrdinalsFieldData.DEFAULT_SCRIPT_FUNCTION
);
}

View File

@ -36,6 +36,7 @@ import org.elasticsearch.index.fielddata.ScriptDocValues;
import org.elasticsearch.index.fielddata.plain.AbstractLeafOrdinalsFieldData;
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;
@ -57,6 +58,7 @@ import java.util.function.Function;
public final class GlobalOrdinalsIndexFieldData extends AbstractIndexComponent implements IndexOrdinalsFieldData, Accountable {
private final String fieldName;
private final ValuesSourceType valuesSourceType;
private final long memorySizeInBytes;
private final OrdinalMap ordinalMap;
@ -65,12 +67,14 @@ public final class GlobalOrdinalsIndexFieldData extends AbstractIndexComponent i
protected GlobalOrdinalsIndexFieldData(IndexSettings indexSettings,
String fieldName,
ValuesSourceType valuesSourceType,
LeafOrdinalsFieldData[] segmentAfd,
OrdinalMap ordinalMap,
long memorySizeInBytes,
Function<SortedSetDocValues, ScriptDocValues<?>> scriptFunction) {
super(indexSettings);
this.fieldName = fieldName;
this.valuesSourceType = valuesSourceType;
this.memorySizeInBytes = memorySizeInBytes;
this.ordinalMap = ordinalMap;
this.segmentAfd = segmentAfd;
@ -101,6 +105,11 @@ public final class GlobalOrdinalsIndexFieldData extends AbstractIndexComponent i
return fieldName;
}
@Override
public ValuesSourceType getValuesSourceType() {
return valuesSourceType;
}
@Override
public SortField sortField(@Nullable Object missingValue, MultiValueMode sortMode, Nested nested, boolean reverse) {
throw new UnsupportedOperationException("no global ordinals sorting yet");
@ -191,6 +200,11 @@ public final class GlobalOrdinalsIndexFieldData extends AbstractIndexComponent i
return fieldName;
}
@Override
public ValuesSourceType getValuesSourceType() {
return valuesSourceType;
}
@Override
public SortField sortField(@Nullable Object missingValue, MultiValueMode sortMode, Nested nested, boolean reverse) {
throw new UnsupportedOperationException("no global ordinals sorting yet");

View File

@ -26,21 +26,29 @@ import org.apache.lucene.util.BytesRef;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.index.AbstractIndexComponent;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.fielddata.LeafFieldData;
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.IndexFieldDataCache;
import org.elasticsearch.index.fielddata.LeafFieldData;
import org.elasticsearch.index.fielddata.RamAccountingTermsEnum;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import java.io.IOException;
public abstract class AbstractIndexFieldData<FD extends LeafFieldData> extends AbstractIndexComponent implements IndexFieldData<FD> {
private final String fieldName;
private ValuesSourceType valuesSourceType;
protected final IndexFieldDataCache cache;
public AbstractIndexFieldData(IndexSettings indexSettings, String fieldName, IndexFieldDataCache cache) {
public AbstractIndexFieldData(
IndexSettings indexSettings,
String fieldName,
ValuesSourceType valuesSourceType,
IndexFieldDataCache cache
) {
super(indexSettings);
this.fieldName = fieldName;
this.valuesSourceType = valuesSourceType;
this.cache = cache;
}
@ -49,6 +57,11 @@ public abstract class AbstractIndexFieldData<FD extends LeafFieldData> extends A
return this.fieldName;
}
@Override
public ValuesSourceType getValuesSourceType() {
return valuesSourceType;
}
@Override
public void clear() {
cache.clear(fieldName);

View File

@ -28,12 +28,13 @@ import org.apache.lucene.index.TermsEnum;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.fielddata.LeafOrdinalsFieldData;
import org.elasticsearch.index.fielddata.IndexFieldDataCache;
import org.elasticsearch.index.fielddata.IndexOrdinalsFieldData;
import org.elasticsearch.index.fielddata.LeafOrdinalsFieldData;
import org.elasticsearch.index.fielddata.ordinals.GlobalOrdinalsBuilder;
import org.elasticsearch.index.fielddata.ordinals.GlobalOrdinalsIndexFieldData;
import org.elasticsearch.indices.breaker.CircuitBreakerService;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import java.io.IOException;
@ -44,10 +45,17 @@ public abstract class AbstractIndexOrdinalsFieldData extends AbstractIndexFieldD
private final int minSegmentSize;
protected final CircuitBreakerService breakerService;
protected AbstractIndexOrdinalsFieldData(IndexSettings indexSettings, String fieldName,
IndexFieldDataCache cache, CircuitBreakerService breakerService,
double minFrequency, double maxFrequency, int minSegmentSize) {
super(indexSettings, fieldName, cache);
protected AbstractIndexOrdinalsFieldData(
IndexSettings indexSettings,
String fieldName,
ValuesSourceType valuesSourceType,
IndexFieldDataCache cache,
CircuitBreakerService breakerService,
double minFrequency,
double maxFrequency,
int minSegmentSize
) {
super(indexSettings, fieldName, valuesSourceType, cache);
this.breakerService = breakerService;
this.minFrequency = minFrequency;
this.maxFrequency = maxFrequency;

View File

@ -38,6 +38,7 @@ 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;
@ -45,10 +46,12 @@ public abstract class AbstractLatLonPointIndexFieldData implements IndexGeoPoint
protected final Index index;
protected final String fieldName;
protected final ValuesSourceType valuesSourceType;
AbstractLatLonPointIndexFieldData(Index index, String fieldName) {
AbstractLatLonPointIndexFieldData(Index index, String fieldName, ValuesSourceType valuesSourceType) {
this.index = index;
this.fieldName = fieldName;
this.valuesSourceType = valuesSourceType;
}
@Override
@ -56,6 +59,11 @@ public abstract class AbstractLatLonPointIndexFieldData implements IndexGeoPoint
return fieldName;
}
@Override
public ValuesSourceType getValuesSourceType() {
return valuesSourceType;
}
@Override
public final void clear() {
// can't do
@ -79,8 +87,8 @@ public abstract class AbstractLatLonPointIndexFieldData implements IndexGeoPoint
}
public static class LatLonPointIndexFieldData extends AbstractLatLonPointIndexFieldData {
public LatLonPointIndexFieldData(Index index, String fieldName) {
super(index, fieldName);
public LatLonPointIndexFieldData(Index index, String fieldName, ValuesSourceType valuesSourceType) {
super(index, fieldName, valuesSourceType);
}
@Override
@ -111,11 +119,16 @@ public abstract class AbstractLatLonPointIndexFieldData implements IndexGeoPoint
}
public static class Builder implements IndexFieldData.Builder {
private final ValuesSourceType valuesSourceType;
public Builder(ValuesSourceType valuesSourceType) {
this.valuesSourceType = valuesSourceType;
}
@Override
public IndexFieldData<?> build(IndexSettings indexSettings, MappedFieldType fieldType, IndexFieldDataCache cache,
CircuitBreakerService breakerService, MapperService mapperService) {
// ignore breaker
return new LatLonPointIndexFieldData(indexSettings.getIndex(), fieldType.name());
return new LatLonPointIndexFieldData(indexSettings.getIndex(), fieldType.name(), valuesSourceType);
}
}
}

View File

@ -34,12 +34,19 @@ 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;
public class BinaryIndexFieldData implements IndexFieldData<BinaryDVLeafFieldData> {
public static class Builder implements IndexFieldData.Builder {
private final ValuesSourceType valuesSourceType;
public Builder(ValuesSourceType valuesSourceType) {
this.valuesSourceType = valuesSourceType;
}
@Override
public BinaryIndexFieldData build(
IndexSettings indexSettings,
@ -49,15 +56,17 @@ public class BinaryIndexFieldData implements IndexFieldData<BinaryDVLeafFieldDat
MapperService mapperService
) {
final String fieldName = fieldType.name();
return new BinaryIndexFieldData(indexSettings.getIndex(), fieldName);
return new BinaryIndexFieldData(indexSettings.getIndex(), fieldName, valuesSourceType);
}
}
protected final Index index;
protected final String fieldName;
protected final ValuesSourceType valuesSourceType;
public BinaryIndexFieldData(Index index, String fieldName) {
public BinaryIndexFieldData(Index index, String fieldName, ValuesSourceType valuesSourceType) {
this.index = index;
this.fieldName = fieldName;
this.valuesSourceType = valuesSourceType;
}
@Override
@ -65,6 +74,11 @@ public class BinaryIndexFieldData implements IndexFieldData<BinaryDVLeafFieldDat
return fieldName;
}
@Override
public ValuesSourceType getValuesSourceType() {
return valuesSourceType;
}
@Override
public final void clear() {
// can't do

View File

@ -34,6 +34,7 @@ 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;
@ -43,10 +44,12 @@ public class BytesBinaryIndexFieldData implements IndexFieldData<BytesBinaryDVLe
protected final Index index;
protected final String fieldName;
protected final ValuesSourceType valuesSourceType;
public BytesBinaryIndexFieldData(Index index, String fieldName) {
public BytesBinaryIndexFieldData(Index index, String fieldName, ValuesSourceType valuesSourceType) {
this.index = index;
this.fieldName = fieldName;
this.valuesSourceType = valuesSourceType;
}
@Override
@ -54,6 +57,11 @@ public class BytesBinaryIndexFieldData implements IndexFieldData<BytesBinaryDVLe
return fieldName;
}
@Override
public ValuesSourceType getValuesSourceType() {
return valuesSourceType;
}
@Override
public final void clear() {
// can't do
@ -90,13 +98,18 @@ public class BytesBinaryIndexFieldData implements IndexFieldData<BytesBinaryDVLe
}
public static class Builder implements IndexFieldData.Builder {
ValuesSourceType valuesSourceType;
public Builder(ValuesSourceType valuesSourceType) {
this.valuesSourceType = valuesSourceType;
}
@Override
public IndexFieldData<?> build(IndexSettings indexSettings, MappedFieldType fieldType, IndexFieldDataCache cache,
CircuitBreakerService breakerService, MapperService mapperService) {
// Ignore breaker
final String fieldName = fieldType.name();
return new BytesBinaryIndexFieldData(indexSettings.getIndex(), fieldName);
return new BytesBinaryIndexFieldData(indexSettings.getIndex(), fieldName, valuesSourceType);
}
}

View File

@ -43,6 +43,7 @@ import org.elasticsearch.index.mapper.TextFieldMapper;
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;
@ -56,15 +57,17 @@ public class ConstantIndexFieldData extends AbstractIndexOrdinalsFieldData {
public static class Builder implements IndexFieldData.Builder {
private final Function<MapperService, String> valueFunction;
private final ValuesSourceType valuesSourceType;
public Builder(Function<MapperService, String> valueFunction) {
public Builder(Function<MapperService, String> valueFunction, ValuesSourceType valuesSourceType) {
this.valueFunction = valueFunction;
this.valuesSourceType = valuesSourceType;
}
@Override
public IndexFieldData<?> build(IndexSettings indexSettings, MappedFieldType fieldType, IndexFieldDataCache cache,
CircuitBreakerService breakerService, MapperService mapperService) {
return new ConstantIndexFieldData(indexSettings, fieldType.name(), valueFunction.apply(mapperService));
return new ConstantIndexFieldData(indexSettings, fieldType.name(), valueFunction.apply(mapperService), valuesSourceType);
}
}
@ -136,8 +139,8 @@ public class ConstantIndexFieldData extends AbstractIndexOrdinalsFieldData {
private final ConstantLeafFieldData atomicFieldData;
private ConstantIndexFieldData(IndexSettings indexSettings, String name, String value) {
super(indexSettings, name, null, null,
private ConstantIndexFieldData(IndexSettings indexSettings, String name, String value, ValuesSourceType valuesSourceType) {
super(indexSettings, name, valuesSourceType, null, null,
TextFieldMapper.Defaults.FIELDDATA_MIN_FREQUENCY,
TextFieldMapper.Defaults.FIELDDATA_MAX_FREQUENCY,
TextFieldMapper.Defaults.FIELDDATA_MIN_SEGMENT_SIZE);

View File

@ -35,12 +35,12 @@ import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.breaker.CircuitBreaker;
import org.elasticsearch.common.util.BigArrays;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.fielddata.LeafOrdinalsFieldData;
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.IndexFieldData.XFieldComparatorSource.Nested;
import org.elasticsearch.index.fielddata.IndexFieldDataCache;
import org.elasticsearch.index.fielddata.IndexOrdinalsFieldData;
import org.elasticsearch.index.fielddata.LeafOrdinalsFieldData;
import org.elasticsearch.index.fielddata.RamAccountingTermsEnum;
import org.elasticsearch.index.fielddata.IndexFieldData.XFieldComparatorSource.Nested;
import org.elasticsearch.index.fielddata.fieldcomparator.BytesRefFieldComparatorSource;
import org.elasticsearch.index.fielddata.ordinals.Ordinals;
import org.elasticsearch.index.fielddata.ordinals.OrdinalsBuilder;
@ -49,6 +49,7 @@ 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;
@ -61,25 +62,34 @@ public class PagedBytesIndexFieldData extends AbstractIndexOrdinalsFieldData {
private final double minFrequency, maxFrequency;
private final int minSegmentSize;
private final ValuesSourceType valuesSourceType;
public Builder(double minFrequency, double maxFrequency, int minSegmentSize) {
public Builder(double minFrequency, double maxFrequency, int minSegmentSize, ValuesSourceType valuesSourceType) {
this.minFrequency = minFrequency;
this.maxFrequency = maxFrequency;
this.minSegmentSize = minSegmentSize;
this.valuesSourceType = valuesSourceType;
}
@Override
public IndexOrdinalsFieldData build(IndexSettings indexSettings, MappedFieldType fieldType,
IndexFieldDataCache cache, CircuitBreakerService breakerService, MapperService mapperService) {
return new PagedBytesIndexFieldData(indexSettings, fieldType.name(), cache, breakerService,
return new PagedBytesIndexFieldData(indexSettings, fieldType.name(), valuesSourceType, cache, breakerService,
minFrequency, maxFrequency, minSegmentSize);
}
}
public PagedBytesIndexFieldData(IndexSettings indexSettings, String fieldName,
IndexFieldDataCache cache, CircuitBreakerService breakerService,
double minFrequency, double maxFrequency, int minSegmentSize) {
super(indexSettings, fieldName, cache, breakerService, minFrequency, maxFrequency, minSegmentSize);
public PagedBytesIndexFieldData(
IndexSettings indexSettings,
String fieldName,
ValuesSourceType valuesSourceType,
IndexFieldDataCache cache,
CircuitBreakerService breakerService,
double minFrequency,
double maxFrequency,
int minSegmentSize
) {
super(indexSettings, fieldName, valuesSourceType, cache, breakerService, minFrequency, maxFrequency, minSegmentSize);
}
@Override

View File

@ -44,6 +44,7 @@ import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.indices.breaker.CircuitBreakerService;
import org.elasticsearch.search.MultiValueMode;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import java.io.IOException;
import java.util.Collection;
@ -79,11 +80,13 @@ public class SortedNumericIndexFieldData extends IndexNumericFieldData {
private final NumericType numericType;
protected final Index index;
protected final String fieldName;
protected final ValuesSourceType valuesSourceType;
public SortedNumericIndexFieldData(Index index, String fieldName, NumericType numericType) {
this.index = index;
this.fieldName = fieldName;
this.numericType = Objects.requireNonNull(numericType);
this.valuesSourceType = numericType.getValuesSourceType();
}
@Override
@ -91,6 +94,11 @@ public class SortedNumericIndexFieldData extends IndexNumericFieldData {
return fieldName;
}
@Override
public ValuesSourceType getValuesSourceType() {
return valuesSourceType;
}
@Override
public final void clear() {
// can't do

View File

@ -47,6 +47,7 @@ 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;
@ -57,13 +58,15 @@ public class SortedSetOrdinalsIndexFieldData implements IndexOrdinalsFieldData {
public static class Builder implements IndexFieldData.Builder {
private final Function<SortedSetDocValues, ScriptDocValues<?>> scriptFunction;
private final ValuesSourceType valuesSourceType;
public Builder() {
this(AbstractLeafOrdinalsFieldData.DEFAULT_SCRIPT_FUNCTION);
public Builder(ValuesSourceType valuesSourceType) {
this(AbstractLeafOrdinalsFieldData.DEFAULT_SCRIPT_FUNCTION, valuesSourceType);
}
public Builder(Function<SortedSetDocValues, ScriptDocValues<?>> scriptFunction) {
public Builder(Function<SortedSetDocValues, ScriptDocValues<?>> scriptFunction, ValuesSourceType valuesSourceType) {
this.scriptFunction = scriptFunction;
this.valuesSourceType = valuesSourceType;
}
@Override
@ -75,7 +78,7 @@ public class SortedSetOrdinalsIndexFieldData implements IndexOrdinalsFieldData {
MapperService mapperService
) {
final String fieldName = fieldType.name();
return new SortedSetOrdinalsIndexFieldData(indexSettings, cache, fieldName, breakerService, scriptFunction);
return new SortedSetOrdinalsIndexFieldData(indexSettings, cache, fieldName, valuesSourceType, breakerService, scriptFunction);
}
}
@ -85,17 +88,20 @@ public class SortedSetOrdinalsIndexFieldData implements IndexOrdinalsFieldData {
private final IndexFieldDataCache cache;
private final CircuitBreakerService breakerService;
private final Function<SortedSetDocValues, ScriptDocValues<?>> scriptFunction;
private final ValuesSourceType valuesSourceType;
private static final Logger logger = LogManager.getLogger(SortedSetOrdinalsIndexFieldData.class);
public SortedSetOrdinalsIndexFieldData(
IndexSettings indexSettings,
IndexFieldDataCache cache,
String fieldName,
ValuesSourceType valuesSourceType,
CircuitBreakerService breakerService,
Function<SortedSetDocValues, ScriptDocValues<?>> scriptFunction
) {
this.index = indexSettings.getIndex();
this.fieldName = fieldName;
this.valuesSourceType = valuesSourceType;
this.indexSettings = indexSettings;
this.cache = cache;
this.breakerService = breakerService;
@ -107,6 +113,11 @@ public class SortedSetOrdinalsIndexFieldData implements IndexOrdinalsFieldData {
return fieldName;
}
@Override
public ValuesSourceType getValuesSourceType() {
return valuesSourceType;
}
@Override
public final void clear() {
// can't do

View File

@ -40,7 +40,6 @@ import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.index.query.QueryShardException;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import java.io.IOException;
import java.time.ZoneId;
@ -134,12 +133,7 @@ public class BinaryFieldMapper extends FieldMapper {
@Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
failIfNoDocValues();
return new BytesBinaryIndexFieldData.Builder();
}
@Override
public ValuesSourceType getValuesSourceType() {
return CoreValuesSourceType.BYTES;
return new BytesBinaryIndexFieldData.Builder(CoreValuesSourceType.BYTES);
}
@Override

View File

@ -39,8 +39,6 @@ import org.elasticsearch.index.fielddata.IndexNumericFieldData.NumericType;
import org.elasticsearch.index.fielddata.plain.SortedNumericIndexFieldData;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import java.io.IOException;
import java.time.ZoneId;
@ -190,11 +188,6 @@ public class BooleanFieldMapper extends FieldMapper {
return new SortedNumericIndexFieldData.Builder(NumericType.BOOLEAN);
}
@Override
public ValuesSourceType getValuesSourceType() {
return CoreValuesSourceType.BOOLEAN;
}
@Override
public DocValueFormat docValueFormat(@Nullable String format, ZoneId timeZone) {
if (format != null) {

View File

@ -54,8 +54,6 @@ import org.elasticsearch.index.query.DateRangeIncludingNowQuery;
import org.elasticsearch.index.query.QueryRewriteContext;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import java.io.IOException;
import java.time.DateTimeException;
@ -534,11 +532,6 @@ public final class DateFieldMapper extends FieldMapper {
return new SortedNumericIndexFieldData.Builder(resolution.numericType());
}
@Override
public ValuesSourceType getValuesSourceType() {
return CoreValuesSourceType.DATE;
}
@Override
public Object valueForDisplay(Object value) {
Long val = (Long) value;

View File

@ -32,7 +32,6 @@ import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.plain.AbstractLatLonPointIndexFieldData;
import org.elasticsearch.index.query.VectorGeoPointShapeQueryProcessor;
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import java.io.IOException;
import java.util.ArrayList;
@ -192,13 +191,9 @@ public class GeoPointFieldMapper extends AbstractPointGeometryFieldMapper<List<?
@Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
failIfNoDocValues();
return new AbstractLatLonPointIndexFieldData.Builder();
return new AbstractLatLonPointIndexFieldData.Builder(CoreValuesSourceType.GEOPOINT);
}
@Override
public ValuesSourceType getValuesSourceType() {
return CoreValuesSourceType.GEOPOINT;
}
}
protected static class ParsedGeoPoint extends GeoPoint implements ParsedPoint {

View File

@ -158,12 +158,6 @@ public class IdFieldMapper extends MetadataFieldMapper {
return new TermInSetQuery(name(), bytesRefs);
}
@Override
public ValuesSourceType getValuesSourceType() {
// TODO: should this even exist? Is aggregating on the ID field valid?
return CoreValuesSourceType.BYTES;
}
@Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
if (indexOptions() == IndexOptions.NONE) {
@ -172,7 +166,8 @@ public class IdFieldMapper extends MetadataFieldMapper {
final IndexFieldData.Builder fieldDataBuilder = new PagedBytesIndexFieldData.Builder(
TextFieldMapper.Defaults.FIELDDATA_MIN_FREQUENCY,
TextFieldMapper.Defaults.FIELDDATA_MAX_FREQUENCY,
TextFieldMapper.Defaults.FIELDDATA_MIN_SEGMENT_SIZE);
TextFieldMapper.Defaults.FIELDDATA_MIN_SEGMENT_SIZE,
CoreValuesSourceType.BYTES);
return new IndexFieldData.Builder() {
@Override
public IndexFieldData<?> build(IndexSettings indexSettings, MappedFieldType fieldType, IndexFieldDataCache cache,
@ -197,6 +192,11 @@ public class IdFieldMapper extends MetadataFieldMapper {
return fieldData.getFieldName();
}
@Override
public ValuesSourceType getValuesSourceType() {
return fieldData.getValuesSourceType();
}
@Override
public LeafFieldData load(LeafReaderContext context) {
return wrap(fieldData.load(context));

View File

@ -29,7 +29,6 @@ import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.plain.ConstantIndexFieldData;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import java.io.IOException;
import java.util.Map;
@ -115,13 +114,9 @@ public class IndexFieldMapper extends MetadataFieldMapper {
@Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
return new ConstantIndexFieldData.Builder(mapperService -> fullyQualifiedIndexName);
return new ConstantIndexFieldData.Builder(mapperService -> fullyQualifiedIndexName, CoreValuesSourceType.BYTES);
}
@Override
public ValuesSourceType getValuesSourceType() {
return CoreValuesSourceType.BYTES;
}
}
private IndexFieldMapper(Settings indexSettings, MappedFieldType existing) {

View File

@ -44,7 +44,6 @@ import org.elasticsearch.index.fielddata.plain.SortedSetOrdinalsIndexFieldData;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import java.io.IOException;
import java.net.InetAddress;
@ -292,12 +291,7 @@ public class IpFieldMapper extends FieldMapper {
@Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
failIfNoDocValues();
return new SortedSetOrdinalsIndexFieldData.Builder(IpScriptDocValues::new);
}
@Override
public ValuesSourceType getValuesSourceType() {
return CoreValuesSourceType.IP;
return new SortedSetOrdinalsIndexFieldData.Builder(IpScriptDocValues::new, CoreValuesSourceType.IP);
}
@Override

View File

@ -43,7 +43,6 @@ import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.plain.SortedSetOrdinalsIndexFieldData;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import java.io.IOException;
import java.util.Iterator;
@ -261,12 +260,7 @@ public final class KeywordFieldMapper extends FieldMapper {
@Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
failIfNoDocValues();
return new SortedSetOrdinalsIndexFieldData.Builder();
}
@Override
public ValuesSourceType getValuesSourceType() {
return CoreValuesSourceType.BYTES;
return new SortedSetOrdinalsIndexFieldData.Builder(CoreValuesSourceType.BYTES);
}
@Override

View File

@ -50,7 +50,6 @@ import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.index.query.QueryShardException;
import org.elasticsearch.index.similarity.SimilarityProvider;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import java.io.IOException;
import java.time.ZoneId;
@ -119,16 +118,6 @@ public abstract class MappedFieldType extends FieldType {
throw new IllegalArgumentException("Fielddata is not supported on field [" + name() + "] of type [" + typeName() + "]");
}
/**
* Returns the {@link ValuesSourceType} which supports this field type. This is tightly coupled to field data and aggregations support,
* so any implementation that returns a value from {@link MappedFieldType#fielddataBuilder} should also return a value from here.
*
* @return The appropriate {@link ValuesSourceType} for this field type.
*/
public ValuesSourceType getValuesSourceType() {
throw new IllegalArgumentException("Aggregations are not supported on field [" + name() + "] of type [" + typeName() + "]");
}
@Override
public boolean equals(Object o) {
if (!super.equals(o)) return false;

View File

@ -56,8 +56,6 @@ import org.elasticsearch.index.fielddata.IndexNumericFieldData.NumericType;
import org.elasticsearch.index.fielddata.plain.SortedNumericIndexFieldData;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import java.io.IOException;
import java.time.ZoneId;
@ -967,11 +965,6 @@ public class NumberFieldMapper extends FieldMapper {
return new SortedNumericIndexFieldData.Builder(type.numericType());
}
@Override
public ValuesSourceType getValuesSourceType() {
return CoreValuesSourceType.NUMERIC;
}
@Override
public Object valueForDisplay(Object value) {
if (value == null) {

View File

@ -46,7 +46,6 @@ import org.elasticsearch.index.fielddata.plain.BinaryIndexFieldData;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import java.io.IOException;
import java.net.InetAddress;
@ -239,12 +238,7 @@ public class RangeFieldMapper extends FieldMapper {
@Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
failIfNoDocValues();
return new BinaryIndexFieldData.Builder();
}
@Override
public ValuesSourceType getValuesSourceType() {
return CoreValuesSourceType.RANGE;
return new BinaryIndexFieldData.Builder(CoreValuesSourceType.RANGE);
}
@Override

View File

@ -37,8 +37,6 @@ import org.elasticsearch.index.fielddata.plain.SortedNumericIndexFieldData;
import org.elasticsearch.index.mapper.ParseContext.Document;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.index.seqno.SequenceNumbers;
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import java.io.IOException;
import java.util.List;
@ -220,10 +218,6 @@ public class SeqNoFieldMapper extends MetadataFieldMapper {
return new SortedNumericIndexFieldData.Builder(NumericType.LONG);
}
@Override
public ValuesSourceType getValuesSourceType() {
return CoreValuesSourceType.NUMERIC;
}
}
public SeqNoFieldMapper(Settings indexSettings) {

View File

@ -69,7 +69,6 @@ import org.elasticsearch.index.fielddata.plain.PagedBytesIndexFieldData;
import org.elasticsearch.index.query.IntervalBuilder;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import java.io.IOException;
import java.util.ArrayList;
@ -772,13 +771,14 @@ public class TextFieldMapper extends FieldMapper {
+ "keyword field instead. Alternatively, set fielddata=true on [" + name() + "] in order to load "
+ "field data by uninverting the inverted index. Note that this can use significant memory.");
}
return new PagedBytesIndexFieldData.Builder(fielddataMinFrequency, fielddataMaxFrequency, fielddataMinSegmentSize);
return new PagedBytesIndexFieldData.Builder(
fielddataMinFrequency,
fielddataMaxFrequency,
fielddataMinSegmentSize,
CoreValuesSourceType.BYTES
);
}
@Override
public ValuesSourceType getValuesSourceType() {
return CoreValuesSourceType.BYTES;
}
}
private int positionIncrementGap;

View File

@ -46,7 +46,6 @@ import org.elasticsearch.index.fielddata.plain.ConstantIndexFieldData;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.index.query.support.QueryParsers;
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import java.io.IOException;
import java.util.Arrays;
@ -117,12 +116,7 @@ public class TypeFieldMapper extends MetadataFieldMapper {
@Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
Function<MapperService, String> typeFunction = mapperService -> mapperService.documentMapper().type();
return new ConstantIndexFieldData.Builder(typeFunction);
}
@Override
public ValuesSourceType getValuesSourceType() {
return CoreValuesSourceType.BYTES;
return new ConstantIndexFieldData.Builder(typeFunction, CoreValuesSourceType.BYTES);
}
@Override

View File

@ -80,7 +80,7 @@ public class GeoHashGridAggregatorFactory extends ValuesSourceAggregatorFactory
boolean collectsFromSingleBucket,
Map<String, Object> metadata) throws IOException {
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry()
.getAggregator(config.valueSourceType(), GeoHashGridAggregationBuilder.NAME);
.getAggregator(config, GeoHashGridAggregationBuilder.NAME);
if (aggregatorSupplier instanceof GeoGridAggregatorSupplier == false) {
throw new AggregationExecutionException("Registry miss-match - expected "
+ GeoGridAggregatorSupplier.class.getName() + ", found [" + aggregatorSupplier.getClass().toString() + "]");

View File

@ -78,7 +78,7 @@ public class GeoTileGridAggregatorFactory extends ValuesSourceAggregatorFactory
boolean collectsFromSingleBucket,
Map<String, Object> metadata) throws IOException {
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry()
.getAggregator(config.valueSourceType(), GeoTileGridAggregationBuilder.NAME);
.getAggregator(config, GeoTileGridAggregationBuilder.NAME);
if (aggregatorSupplier instanceof GeoGridAggregatorSupplier == false) {
throw new AggregationExecutionException("Registry miss-match - expected "
+ GeoGridAggregatorSupplier.class.getName() + ", found [" + aggregatorSupplier.getClass().toString() + "]");

View File

@ -72,7 +72,7 @@ public final class AutoDateHistogramAggregatorFactory extends ValuesSourceAggreg
if (collectsFromSingleBucket == false) {
return asMultiBucketAggregator(this, searchContext, parent);
}
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config.valueSourceType(),
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config,
AutoDateHistogramAggregationBuilder.NAME);
if (aggregatorSupplier instanceof AutoDateHistogramAggregatorSupplier == false) {
throw new AggregationExecutionException("Registry miss-match - expected AutoDateHistogramAggregationSupplier, found [" +

View File

@ -81,7 +81,7 @@ public final class DateHistogramAggregatorFactory extends ValuesSourceAggregator
Aggregator parent,
boolean collectsFromSingleBucket,
Map<String, Object> metadata) throws IOException {
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config.valueSourceType(),
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config,
DateHistogramAggregationBuilder.NAME);
if (aggregatorSupplier instanceof DateHistogramAggregationSupplier == false) {
throw new AggregationExecutionException("Registry miss-match - expected DateHistogramAggregationSupplier, found [" +

View File

@ -92,7 +92,7 @@ public final class HistogramAggregatorFactory extends ValuesSourceAggregatorFact
Aggregator parent,
boolean collectsFromSingleBucket,
Map<String, Object> metadata) throws IOException {
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config.valueSourceType(),
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config,
HistogramAggregationBuilder.NAME);
if (aggregatorSupplier instanceof HistogramAggregatorSupplier == false) {
throw new AggregationExecutionException("Registry miss-match - expected HistogramAggregatorSupplier, found [" +

View File

@ -20,9 +20,11 @@
package org.elasticsearch.search.aggregations.bucket.missing;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.search.aggregations.AggregationExecutionException;
import org.elasticsearch.search.aggregations.Aggregator;
import org.elasticsearch.search.aggregations.AggregatorFactories;
import org.elasticsearch.search.aggregations.AggregatorFactory;
import org.elasticsearch.search.aggregations.support.AggregatorSupplier;
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
import org.elasticsearch.search.aggregations.support.ValuesSource;
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
@ -59,7 +61,15 @@ public class MissingAggregatorFactory extends ValuesSourceAggregatorFactory {
Aggregator parent,
boolean collectsFromSingleBucket,
Map<String, Object> metadata) throws IOException {
return new MissingAggregator(name, factories, valuesSource, searchContext, parent, metadata);
final AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry()
.getAggregator(config, MissingAggregationBuilder.NAME);
if (aggregatorSupplier instanceof MissingAggregatorSupplier == false) {
throw new AggregationExecutionException("Registry miss-match - expected MissingAggregatorSupplier, found [" +
aggregatorSupplier.getClass().toString() + "]");
}
return (MissingAggregator) ((MissingAggregatorSupplier) aggregatorSupplier)
.build(name, factories, valuesSource, searchContext, parent, metadata);
}
}

View File

@ -82,7 +82,8 @@ public class AbstractRangeAggregatorFactory<R extends Range> extends ValuesSourc
Aggregator parent,
boolean collectsFromSingleBucket,
Map<String, Object> metadata) throws IOException {
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config.valueSourceType(),
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config,
aggregationTypeName);
if (aggregatorSupplier instanceof RangeAggregatorSupplier == false) {
throw new AggregationExecutionException("Registry miss-match - expected RangeAggregatorSupplier, found [" +

View File

@ -66,7 +66,7 @@ public class BinaryRangeAggregatorFactory extends ValuesSourceAggregatorFactory
SearchContext searchContext, Aggregator parent,
boolean collectsFromSingleBucket,
Map<String, Object> metadata) throws IOException {
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config.valueSourceType(),
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config,
IpRangeAggregationBuilder.NAME);
if (aggregatorSupplier instanceof IpRangeAggregatorSupplier == false) {

View File

@ -91,7 +91,7 @@ public class GeoDistanceRangeAggregatorFactory extends ValuesSourceAggregatorFac
boolean collectsFromSingleBucket,
Map<String, Object> metadata) throws IOException {
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry()
.getAggregator(config.valueSourceType(), GeoDistanceAggregationBuilder.NAME);
.getAggregator(config, GeoDistanceAggregationBuilder.NAME);
if (aggregatorSupplier instanceof GeoDistanceAggregatorSupplier == false) {
throw new AggregationExecutionException("Registry miss-match - expected "
+ GeoDistanceAggregatorSupplier.class.getName() + ", found [" + aggregatorSupplier.getClass().toString() + "]");

View File

@ -94,7 +94,7 @@ public class DiversifiedAggregatorFactory extends ValuesSourceAggregatorFactory
boolean collectsFromSingleBucket,
Map<String, Object> metadata) throws IOException {
AggregatorSupplier supplier = queryShardContext.getValuesSourceRegistry().getAggregator(config.valueSourceType(),
AggregatorSupplier supplier = queryShardContext.getValuesSourceRegistry().getAggregator(config,
DiversifiedAggregationBuilder.NAME);
if (supplier instanceof DiversifiedAggregatorSupplier == false) {
throw new AggregationExecutionException("Registry miss-match - expected " + DiversifiedAggregatorSupplier.class.toString() +

View File

@ -160,7 +160,7 @@ public class RareTermsAggregatorFactory extends ValuesSourceAggregatorFactory {
return asMultiBucketAggregator(this, searchContext, parent);
}
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config.valueSourceType(),
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config,
RareTermsAggregationBuilder.NAME);
if (aggregatorSupplier instanceof RareTermsAggregatorSupplier == false) {
throw new AggregationExecutionException("Registry miss-match - expected RareTermsAggregatorSupplier, found [" +

View File

@ -300,7 +300,7 @@ public class SignificantTermsAggregatorFactory extends ValuesSourceAggregatorFac
Aggregator parent,
boolean collectsFromSingleBucket,
Map<String, Object> metadata) throws IOException {
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config.valueSourceType(),
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config,
SignificantTermsAggregationBuilder.NAME);
if (aggregatorSupplier instanceof SignificantTermsAggregatorSupplier == false) {
throw new AggregationExecutionException("Registry miss-match - expected SignificantTermsAggregatorSupplier, found [" +

View File

@ -240,7 +240,7 @@ public class TermsAggregatorFactory extends ValuesSourceAggregatorFactory {
Aggregator parent,
boolean collectsFromSingleBucket,
Map<String, Object> metadata) throws IOException {
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config.valueSourceType(),
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config,
TermsAggregationBuilder.NAME);
if (aggregatorSupplier instanceof TermsAggregatorSupplier == false) {
throw new AggregationExecutionException("Registry miss-match - expected TermsAggregatorSupplier, found [" +

View File

@ -63,7 +63,7 @@ class AvgAggregatorFactory extends ValuesSourceAggregatorFactory {
Aggregator parent,
boolean collectsFromSingleBucket,
Map<String, Object> metadata) throws IOException {
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config.valueSourceType(),
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config,
AvgAggregationBuilder.NAME);
if (aggregatorSupplier instanceof MetricAggregatorSupplier == false) {

View File

@ -67,7 +67,7 @@ class CardinalityAggregatorFactory extends ValuesSourceAggregatorFactory {
Aggregator parent,
boolean collectsFromSingleBucket,
Map<String, Object> metadata) throws IOException {
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config.valueSourceType(),
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config,
CardinalityAggregationBuilder.NAME);
if (aggregatorSupplier instanceof CardinalityAggregatorSupplier == false) {
throw new AggregationExecutionException("Registry miss-match - expected CardinalityAggregatorSupplier, found [" +

View File

@ -24,6 +24,7 @@ import org.elasticsearch.search.aggregations.AggregationExecutionException;
import org.elasticsearch.search.aggregations.Aggregator;
import org.elasticsearch.search.aggregations.AggregatorFactories;
import org.elasticsearch.search.aggregations.AggregatorFactory;
import org.elasticsearch.search.aggregations.support.AggregatorSupplier;
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
import org.elasticsearch.search.aggregations.support.ValuesSource;
import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric;
@ -70,9 +71,12 @@ class ExtendedStatsAggregatorFactory extends ValuesSourceAggregatorFactory {
Aggregator parent,
boolean collectsFromSingleBucket,
Map<String, Object> metadata) throws IOException {
if (valuesSource instanceof Numeric == false) {
throw new AggregationExecutionException("ValuesSource type " + valuesSource.toString() + "is not supported for aggregation " +
this.name());
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config,
ExtendedStatsAggregationBuilder.NAME);
if (aggregatorSupplier instanceof ExtendedStatsAggregatorProvider == false) {
throw new AggregationExecutionException("Registry miss-match - expected ExtendedStatsAggregatorProvider, found [" +
aggregatorSupplier.getClass().toString() + "]");
}
return new ExtendedStatsAggregator(name, (Numeric) valuesSource, config.format(), searchContext,
parent, sigma, metadata);

View File

@ -64,7 +64,7 @@ class GeoBoundsAggregatorFactory extends ValuesSourceAggregatorFactory {
boolean collectsFromSingleBucket,
Map<String, Object> metadata) throws IOException {
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry()
.getAggregator(config.valueSourceType(), GeoBoundsAggregationBuilder.NAME);
.getAggregator(config, GeoBoundsAggregationBuilder.NAME);
if (aggregatorSupplier instanceof GeoBoundsAggregatorSupplier == false) {
throw new AggregationExecutionException("Registry miss-match - expected "

View File

@ -60,7 +60,7 @@ class GeoCentroidAggregatorFactory extends ValuesSourceAggregatorFactory {
boolean collectsFromSingleBucket,
Map<String, Object> metadata) throws IOException {
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config.valueSourceType(),
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config,
GeoCentroidAggregationBuilder.NAME);
if (aggregatorSupplier instanceof GeoCentroidAggregatorSupplier == false) {
throw new AggregationExecutionException("Registry miss-match - expected "

View File

@ -62,7 +62,7 @@ class MaxAggregatorFactory extends ValuesSourceAggregatorFactory {
Aggregator parent,
boolean collectsFromSingleBucket,
Map<String, Object> metadata) throws IOException {
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config.valueSourceType(),
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config,
MaxAggregationBuilder.NAME);
if (aggregatorSupplier instanceof MetricAggregatorSupplier == false) {

View File

@ -78,7 +78,7 @@ public class MedianAbsoluteDeviationAggregatorFactory extends ValuesSourceAggreg
Aggregator parent,
boolean collectsFromSingleBucket,
Map<String, Object> metadata) throws IOException {
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config.valueSourceType(),
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config,
MedianAbsoluteDeviationAggregationBuilder.NAME);
if (aggregatorSupplier instanceof MedianAbsoluteDeviationAggregatorSupplier == false) {

View File

@ -62,7 +62,7 @@ class MinAggregatorFactory extends ValuesSourceAggregatorFactory {
Aggregator parent,
boolean collectsFromSingleBucket,
Map<String, Object> metadata) throws IOException {
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config.valueSourceType(),
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config,
MinAggregationBuilder.NAME);
if (aggregatorSupplier instanceof MetricAggregatorSupplier == false) {

View File

@ -89,7 +89,7 @@ class PercentileRanksAggregatorFactory extends ValuesSourceAggregatorFactory {
Aggregator parent,
boolean collectsFromSingleBucket,
Map<String, Object> metadata) throws IOException {
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config.valueSourceType(),
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config,
PercentileRanksAggregationBuilder.NAME);
if (aggregatorSupplier instanceof PercentilesAggregatorSupplier == false) {

View File

@ -89,7 +89,7 @@ class PercentilesAggregatorFactory extends ValuesSourceAggregatorFactory {
boolean collectsFromSingleBucket,
Map<String, Object> metadata) throws IOException {
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config.valueSourceType(),
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config,
PercentilesAggregationBuilder.NAME);
if (aggregatorSupplier instanceof PercentilesAggregatorSupplier == false) {

View File

@ -65,7 +65,7 @@ class StatsAggregatorFactory extends ValuesSourceAggregatorFactory {
Aggregator parent,
boolean collectsFromSingleBucket,
Map<String, Object> metadata) throws IOException {
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config.valueSourceType(),
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config,
StatsAggregationBuilder.NAME);
if (aggregatorSupplier instanceof MetricAggregatorSupplier == false) {

View File

@ -66,7 +66,7 @@ class SumAggregatorFactory extends ValuesSourceAggregatorFactory {
Aggregator parent,
boolean collectsFromSingleBucket,
Map<String, Object> metadata) throws IOException {
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config.valueSourceType(),
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config,
SumAggregationBuilder.NAME);
if (aggregatorSupplier instanceof MetricAggregatorSupplier == false) {

View File

@ -61,7 +61,7 @@ class ValueCountAggregatorFactory extends ValuesSourceAggregatorFactory {
Aggregator parent,
boolean collectsFromSingleBucket,
Map<String, Object> metadata) throws IOException {
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config.valueSourceType(),
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config,
ValueCountAggregationBuilder.NAME);
if (aggregatorSupplier instanceof ValueCountAggregatorSupplier == false) {
throw new AggregationExecutionException("Registry miss-match - expected ValueCountAggregatorSupplier, found [" +

View File

@ -346,6 +346,11 @@ public abstract class ValuesSourceAggregationBuilder<AB extends ValuesSourceAggr
protected final ValuesSourceAggregatorFactory doBuild(QueryShardContext queryShardContext, AggregatorFactory parent,
Builder subFactoriesBuilder) throws IOException {
ValuesSourceConfig config = resolveConfig(queryShardContext);
if (queryShardContext.getValuesSourceRegistry().isRegistered(getType())) {
// Only test if the values source type is valid if the aggregation uses the registry
AggregatorSupplier supplier = queryShardContext.getValuesSourceRegistry().getAggregator(config, getType());
}
// TODO: We should pass the supplier in from here. Right now this just checks that the VST is valid
ValuesSourceAggregatorFactory factory = innerBuild(queryShardContext, config, parent, subFactoriesBuilder);
return factory;
}

View File

@ -66,7 +66,8 @@ public class ValuesSourceConfig {
String aggregationName) {
return internalResolve(context, userValueTypeHint, field, script, missing, timeZone, format, defaultValueSourceType,
aggregationName, ValuesSourceConfig::getMappingFromRegistry);
ValuesSourceConfig::getMappingFromRegistry
);
}
/**
@ -93,7 +94,15 @@ public class ValuesSourceConfig {
ZoneId timeZone,
String format,
ValuesSourceType defaultValueSourceType) {
return internalResolve(context, userValueTypeHint, field, script, missing, timeZone, format, defaultValueSourceType, null,
return internalResolve(
context,
userValueTypeHint,
field,
script,
missing,
timeZone,
format,
defaultValueSourceType,
ValuesSourceConfig::getLegacyMapping);
}
@ -105,13 +114,13 @@ public class ValuesSourceConfig {
ZoneId timeZone,
String format,
ValuesSourceType defaultValueSourceType,
String aggregationName,
FieldResolver fieldResolver
) {
ValuesSourceConfig config;
MappedFieldType fieldType = null;
ValuesSourceType valuesSourceType = null;
ValueType scriptValueType = userValueTypeHint;
FieldContext fieldContext = null;
AggregationScript.LeafFactory aggregationScript = createScript(script, context); // returns null if script is null
boolean unmapped = false;
if (userValueTypeHint != null) {
@ -134,16 +143,18 @@ public class ValuesSourceConfig {
*/
unmapped = true;
aggregationScript = null; // Value scripts are not allowed on unmapped fields. What would that do, anyway?
} else if (valuesSourceType == null) {
} else {
fieldContext = new FieldContext(fieldType.name(), context.getForField(fieldType), fieldType);
if (valuesSourceType == null) {
// We have a field, and the user didn't specify a type, so get the type from the field
valuesSourceType = fieldResolver.getValuesSourceType(context, fieldType, aggregationName, userValueTypeHint,
defaultValueSourceType);
valuesSourceType = fieldResolver.getValuesSourceType(fieldContext, userValueTypeHint, defaultValueSourceType);
}
}
}
if (valuesSourceType == null) {
valuesSourceType = defaultValueSourceType;
}
config = new ValuesSourceConfig(valuesSourceType, fieldType, unmapped, aggregationScript, scriptValueType , context);
config = new ValuesSourceConfig(valuesSourceType, fieldContext, unmapped, aggregationScript, scriptValueType, context::nowInMillis);
config.format(resolveFormat(format, valuesSourceType, timeZone, fieldType));
config.missing(missing);
config.timezone(timeZone);
@ -153,37 +164,31 @@ public class ValuesSourceConfig {
@FunctionalInterface
private interface FieldResolver {
ValuesSourceType getValuesSourceType(
QueryShardContext context,
MappedFieldType fieldType,
String aggregationName,
FieldContext fieldContext,
ValueType userValueTypeHint,
ValuesSourceType defaultValuesSourceType);
}
private static ValuesSourceType getMappingFromRegistry(
QueryShardContext context,
MappedFieldType fieldType,
String aggregationName,
FieldContext fieldContext,
ValueType userValueTypeHint,
ValuesSourceType defaultValuesSourceType) {
IndexFieldData<?> indexFieldData = context.getForField(fieldType);
return context.getValuesSourceRegistry().getValuesSourceType(fieldType, aggregationName, indexFieldData,
userValueTypeHint, defaultValuesSourceType);
ValuesSourceType defaultValuesSourceType
) {
return fieldContext.indexFieldData().getValuesSourceType();
}
private static ValuesSourceType getLegacyMapping(
QueryShardContext context,
MappedFieldType fieldType,
String aggregationName,
FieldContext fieldContext,
ValueType userValueTypeHint,
ValuesSourceType defaultValuesSourceType) {
IndexFieldData<?> indexFieldData = context.getForField(fieldType);
ValuesSourceType defaultValuesSourceType
) {
IndexFieldData<?> indexFieldData = fieldContext.indexFieldData();
if (indexFieldData instanceof IndexNumericFieldData) {
return CoreValuesSourceType.NUMERIC;
} else if (indexFieldData instanceof IndexGeoPointFieldData) {
return CoreValuesSourceType.GEOPOINT;
} else if (fieldType instanceof RangeFieldMapper.RangeFieldType) {
} else if (fieldContext.fieldType() instanceof RangeFieldMapper.RangeFieldType) {
return CoreValuesSourceType.RANGE;
} else {
if (userValueTypeHint == null) {
@ -192,7 +197,6 @@ public class ValuesSourceConfig {
return userValueTypeHint.getValuesSourceType();
}
}
}
private static AggregationScript.LeafFactory createScript(Script script, QueryShardContext context) {
@ -220,14 +224,22 @@ public class ValuesSourceConfig {
*/
public static ValuesSourceConfig resolveFieldOnly(MappedFieldType fieldType,
QueryShardContext queryShardContext) {
return new ValuesSourceConfig(fieldType.getValuesSourceType(), fieldType, false, null, null, queryShardContext);
FieldContext fieldContext = new FieldContext(fieldType.name(), queryShardContext.getForField(fieldType), fieldType);
return new ValuesSourceConfig(
fieldContext.indexFieldData().getValuesSourceType(),
fieldContext,
false,
null,
null,
queryShardContext::nowInMillis
);
}
/**
* Convenience method for creating unmapped configs
*/
public static ValuesSourceConfig resolveUnmapped(ValuesSourceType valuesSourceType, QueryShardContext queryShardContext) {
return new ValuesSourceConfig(valuesSourceType, null, true, null, null, queryShardContext);
return new ValuesSourceConfig(valuesSourceType, null, true, null, null, queryShardContext::nowInMillis);
}
private final ValuesSourceType valuesSourceType;
@ -241,23 +253,23 @@ public class ValuesSourceConfig {
private LongSupplier nowSupplier;
public ValuesSourceConfig(ValuesSourceType valuesSourceType,
MappedFieldType fieldType,
public ValuesSourceConfig(
ValuesSourceType valuesSourceType,
FieldContext fieldContext,
boolean unmapped,
AggregationScript.LeafFactory script,
ValueType scriptValueType,
QueryShardContext queryShardContext) {
if (unmapped && fieldType != null) {
LongSupplier nowSupplier
) {
if (unmapped && fieldContext != null) {
throw new IllegalStateException("value source config is invalid; marked as unmapped but specified a mapped field");
}
this.valuesSourceType = valuesSourceType;
if (fieldType != null) {
this.fieldContext = new FieldContext(fieldType.name(), queryShardContext.getForField(fieldType), fieldType);
}
this.fieldContext = fieldContext;
this.unmapped = unmapped;
this.script = script;
this.scriptValueType = scriptValueType;
this.nowSupplier = queryShardContext::nowInMillis;
this.nowSupplier = nowSupplier;
}

View File

@ -18,11 +18,7 @@
*/
package org.elasticsearch.search.aggregations.support;
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.IndexGeoPointFieldData;
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.RangeFieldMapper;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.search.SearchModule;
import org.elasticsearch.search.aggregations.AggregationExecutionException;
@ -116,51 +112,27 @@ public class ValuesSourceRegistry {
return supportedTypes.get(valuesSourceType);
}
public AggregatorSupplier getAggregator(ValuesSourceType valuesSourceType, String aggregationName) {
if (aggregationName != null && aggregatorRegistry.containsKey(aggregationName)) {
AggregatorSupplier supplier = findMatchingSuppier(valuesSourceType, aggregatorRegistry.get(aggregationName));
if (supplier == null) {
throw new AggregationExecutionException("ValuesSource type " + valuesSourceType.toString() +
" is not supported for aggregation" + aggregationName);
public boolean isRegistered(String aggregationName) {
return aggregatorRegistry.containsKey(aggregationName);
}
public AggregatorSupplier getAggregator(ValuesSourceConfig valuesSourceConfig, String aggregationName) {
if (aggregationName != null && aggregatorRegistry.containsKey(aggregationName)) {
AggregatorSupplier supplier = findMatchingSuppier(
valuesSourceConfig.valueSourceType(),
aggregatorRegistry.get(aggregationName)
);
if (supplier == null) {
// TODO: push building the description into ValuesSourceConfig
MappedFieldType fieldType = valuesSourceConfig.fieldContext().fieldType();
String fieldDescription = fieldType.typeName() + "(" + fieldType.toString() + ")";
throw new IllegalArgumentException("Field [" + fieldType.name() + "] of type [" + fieldDescription +
"] is not supported for aggregation [" + aggregationName + "]"); }
return supplier;
}
throw new AggregationExecutionException("Unregistered Aggregation [" + aggregationName + "]");
}
public ValuesSourceType getValuesSourceType(MappedFieldType fieldType, String aggregationName,
// TODO: the following arguments are only needed for the legacy case
IndexFieldData<?> indexFieldData,
ValueType valueType,
ValuesSourceType defaultValuesSourceType) {
if (aggregationName != null && aggregatorRegistry.containsKey(aggregationName)) {
// This will throw if the field doesn't support values sources, although really we probably threw much earlier in that case
ValuesSourceType valuesSourceType = fieldType.getValuesSourceType();
if (aggregatorRegistry.get(aggregationName) != null
&& findMatchingSuppier(valuesSourceType, aggregatorRegistry.get(aggregationName)) != null) {
return valuesSourceType;
}
String fieldDescription = fieldType.typeName() + "(" + fieldType.toString() + ")";
throw new IllegalArgumentException("Field [" + fieldType.name() + "] of type [" + fieldDescription +
"] is not supported for aggregation [" + aggregationName + "]");
} else {
// TODO: Legacy resolve logic; remove this after converting all aggregations to the new system
if (indexFieldData instanceof IndexNumericFieldData) {
return CoreValuesSourceType.NUMERIC;
} else if (indexFieldData instanceof IndexGeoPointFieldData) {
return CoreValuesSourceType.GEOPOINT;
} else if (fieldType instanceof RangeFieldMapper.RangeFieldType) {
return CoreValuesSourceType.RANGE;
} else {
if (valueType == null) {
return defaultValuesSourceType;
} else {
return valueType.getValuesSourceType();
}
}
}
}
public AggregationUsageService getUsageService() {
return usageService;
}

View File

@ -0,0 +1,77 @@
/*
* 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.search.aggregations.support;
/**
* <p>
* This package holds shared code for the aggregations framework, especially around dealing with values.
* </p>
*
* <h2> Key Classes </h2>
*
* <h3> {@link org.elasticsearch.search.aggregations.support.ValuesSource} and its subclasses </h3>
* <p>
* These are thin wrappers which provide a unified interface to different ways of getting input data (e.g. DocValues from Lucene, or script
* output). A class hierarchy defines the type of values returned by the source. The top level sub-classes define type-specific behavior,
* such as {@link org.elasticsearch.search.aggregations.support.ValuesSource.Numeric#isFloatingPoint()}. Second level subclasses are
* then specialized based on where they read values from, e.g. script or field cases. There are also adapter classes like
* {@link org.elasticsearch.search.aggregations.bucket.geogrid.CellIdSource} which do run-time conversion from one type to another, often
* dependent on a user specified parameter (precision in that case).
* </p>
*
* <h3> {@link org.elasticsearch.search.aggregations.support.ValuesSourceRegistry} </h3>
* <p>
* ValuesSourceRegistry stores the mappings for what types are supported by what aggregations. It is configured at startup, when
* {@link org.elasticsearch.search.SearchModule} is configuring aggregations. It shouldn't be necessary to access the registry in most
* cases, but you can get a read copy from {@link org.elasticsearch.index.query.QueryShardContext#getValuesSourceRegistry()} if necessary.
* </p>
*
* <h3> {@link org.elasticsearch.search.aggregations.support.ValuesSourceType} </h3>
* <p>
* ValuesSourceTypes are the quantum of support in the aggregations framework, and provide a common language between fields and
* aggregations. Fields which support aggregation set a ValuesSourceType on their {@link org.elasticsearch.index.fielddata.IndexFieldData}
* implementations, and aggregations register what types they support via one of the
* {@link org.elasticsearch.search.aggregations.support.ValuesSourceRegistry.Builder#register} methods. The VaulesSourceType itself holds
* information on how to with values of that type, including methods for creating
* {@link org.elasticsearch.search.aggregations.support.ValuesSource} instances and {@link org.elasticsearch.search.DocValueFormat}
* instances.
* </p>
*
* <h3> {@link org.elasticsearch.search.aggregations.support.ValuesSourceConfig} </h3>
* <p>
* There are two things going on in ValuesSourceConfig. First, there is a collection of static factory methods to build valid configs for
* different situations. {@link org.elasticsearch.search.aggregations.support.ValuesSourceAggregationBuilder#resolveConfig} has a good
* default for what to call here and generally aggregations shouldn't need to deviate from that.
* </p>
*
* <p>
* Once properly constructed, the ValuesSourceConfig provides access to the ValuesSource instance, as well as related information like the
* formatter. Aggregations are free to use this information as needed, such as Max and Min which inspect the field context to see if they
* can apply an optimization.
* </p>
*
* <h2> Classes we are trying to phase out </h2>
* <h3> {@link org.elasticsearch.search.aggregations.support.ValueType} </h3>
* <p>
* This class is primarily used for parsing user type hints, and is deprecated for new use. Work is ongoing to remove it from existing
* code.
* </p>
*
*/

View File

@ -41,6 +41,7 @@ import org.elasticsearch.index.fielddata.plain.SortedSetOrdinalsIndexFieldData;
import org.elasticsearch.index.mapper.TextFieldMapper;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.indices.breaker.NoneCircuitBreakerService;
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.FieldMaskingReader;
@ -88,15 +89,21 @@ public class FieldDataCacheTests extends ESTestCase {
}
private SortedSetOrdinalsIndexFieldData createSortedDV(String fieldName, IndexFieldDataCache indexFieldDataCache) {
return new SortedSetOrdinalsIndexFieldData(createIndexSettings(), indexFieldDataCache, fieldName, new NoneCircuitBreakerService(),
AbstractLeafOrdinalsFieldData.DEFAULT_SCRIPT_FUNCTION);
return new SortedSetOrdinalsIndexFieldData(createIndexSettings(), indexFieldDataCache, fieldName, CoreValuesSourceType.BYTES,
new NoneCircuitBreakerService(), AbstractLeafOrdinalsFieldData.DEFAULT_SCRIPT_FUNCTION);
}
private PagedBytesIndexFieldData createPagedBytes(String fieldName, IndexFieldDataCache indexFieldDataCache) {
return new PagedBytesIndexFieldData(createIndexSettings(), fieldName, indexFieldDataCache, new NoneCircuitBreakerService(),
return new PagedBytesIndexFieldData(
createIndexSettings(),
fieldName,
CoreValuesSourceType.BYTES,
indexFieldDataCache,
new NoneCircuitBreakerService(),
TextFieldMapper.Defaults.FIELDDATA_MIN_FREQUENCY,
TextFieldMapper.Defaults.FIELDDATA_MAX_FREQUENCY,
TextFieldMapper.Defaults.FIELDDATA_MIN_SEGMENT_SIZE);
TextFieldMapper.Defaults.FIELDDATA_MIN_SEGMENT_SIZE
);
}
private IndexSettings createIndexSettings() {

View File

@ -28,6 +28,7 @@ import org.elasticsearch.index.fielddata.IndexFieldData.XFieldComparatorSource.N
import org.elasticsearch.index.fielddata.fieldcomparator.BytesRefFieldComparatorSource;
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;
@ -48,6 +49,11 @@ public class NoOrdinalsStringFieldDataTests extends PagedBytesStringFieldDataTes
return in.getFieldName();
}
@Override
public ValuesSourceType getValuesSourceType() {
return in.getValuesSourceType();
}
@Override
public LeafFieldData load(LeafReaderContext context) {
return in.load(context);

View File

@ -64,6 +64,7 @@ import org.elasticsearch.index.fielddata.SortedBinaryDocValues;
import org.elasticsearch.index.fielddata.SortedNumericDoubleValues;
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 org.elasticsearch.test.ESTestCase;
@ -93,6 +94,11 @@ public class FunctionScoreTests extends ESTestCase {
return "test";
}
@Override
public ValuesSourceType getValuesSourceType() {
throw new UnsupportedOperationException(UNSUPPORTED);
}
@Override
public LeafFieldData load(LeafReaderContext context) {
return new LeafFieldData() {
@ -181,6 +187,11 @@ public class FunctionScoreTests extends ESTestCase {
return "test";
}
@Override
public ValuesSourceType getValuesSourceType() {
throw new UnsupportedOperationException(UNSUPPORTED);
}
@Override
public LeafNumericFieldData load(LeafReaderContext context) {
return new LeafNumericFieldData() {

View File

@ -165,7 +165,6 @@ public abstract class AggregatorTestCase extends ESTestCase {
TYPE_TEST_BLACKLIST = blacklist;
}
/**
* Allows subclasses to provide alternate names for the provided field type, which
* can be useful when testing aggregations on field aliases.
@ -720,7 +719,7 @@ public abstract class AggregatorTestCase extends ESTestCase {
IndexSearcher indexSearcher = newIndexSearcher(indexReader);
AggregationBuilder aggregationBuilder = createAggBuilderForTypeTest(fieldType, fieldName);
ValuesSourceType vst = fieldType.getValuesSourceType();
ValuesSourceType vst = fieldToVST(fieldType);
// TODO in the future we can make this more explicit with expectThrows(), when the exceptions are standardized
AssertionError failure = null;
try {
@ -744,6 +743,11 @@ public abstract class AggregatorTestCase extends ESTestCase {
}
}
private ValuesSourceType fieldToVST(MappedFieldType fieldType) {
return fieldType.fielddataBuilder("")
.build(createIndexSettings(), fieldType, null, null, null).getValuesSourceType();
}
/**
* Helper method to write a single document with a single value specific to the requested fieldType.
*
@ -753,7 +757,7 @@ public abstract class AggregatorTestCase extends ESTestCase {
private void writeTestDoc(MappedFieldType fieldType, String fieldName, RandomIndexWriter iw) throws IOException {
String typeName = fieldType.typeName();
ValuesSourceType vst = fieldType.getValuesSourceType();
ValuesSourceType vst = fieldToVST(fieldType);
Document doc = new Document();
String json;

View File

@ -59,7 +59,7 @@ public class BoxplotAggregatorFactory extends ValuesSourceAggregatorFactory {
Aggregator parent,
boolean collectsFromSingleBucket,
Map<String, Object> metadata) throws IOException {
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config.valueSourceType(),
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config,
BoxplotAggregationBuilder.NAME);
if (aggregatorSupplier instanceof BoxplotAggregatorSupplier == false) {

View File

@ -50,7 +50,6 @@ import org.elasticsearch.index.query.QueryShardException;
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 org.elasticsearch.xpack.analytics.aggregations.support.AnalyticsValuesSourceType;
@ -198,7 +197,7 @@ public class HistogramFieldMapper extends FieldMapper {
public IndexFieldData<?> build(IndexSettings indexSettings, MappedFieldType fieldType, IndexFieldDataCache cache,
CircuitBreakerService breakerService, MapperService mapperService) {
return new IndexHistogramFieldData(indexSettings.getIndex(), fieldType.name()) {
return new IndexHistogramFieldData(indexSettings.getIndex(), fieldType.name(), AnalyticsValuesSourceType.HISTOGRAM) {
@Override
public LeafHistogramFieldData load(LeafReaderContext context) {
@ -275,11 +274,6 @@ public class HistogramFieldMapper extends FieldMapper {
};
}
@Override
public ValuesSourceType getValuesSourceType() {
return AnalyticsValuesSourceType.HISTOGRAM;
}
@Override
public Query existsQuery(QueryShardContext context) {
if (hasDocValues()) {

View File

@ -53,7 +53,7 @@ class StringStatsAggregatorFactory extends ValuesSourceAggregatorFactory {
Aggregator parent,
boolean collectsFromSingleBucket,
Map<String, Object> metadata) throws IOException {
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config.valueSourceType(),
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config,
StringStatsAggregationBuilder.NAME);
if (aggregatorSupplier instanceof StringStatsAggregatorSupplier == false) {

View File

@ -37,7 +37,6 @@ import org.elasticsearch.index.mapper.ParseContext;
import org.elasticsearch.index.mapper.TypeParsers;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import java.io.IOException;
import java.time.ZoneId;
@ -158,7 +157,7 @@ public class ConstantKeywordFieldMapper extends FieldMapper {
@Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
return new ConstantIndexFieldData.Builder(mapperService -> value);
return new ConstantIndexFieldData.Builder(mapperService -> value, CoreValuesSourceType.BYTES);
}
@Override
@ -240,10 +239,6 @@ public class ConstantKeywordFieldMapper extends FieldMapper {
}
}
@Override
public ValuesSourceType getValuesSourceType() {
return CoreValuesSourceType.BYTES;
}
}
ConstantKeywordFieldMapper(String simpleName, MappedFieldType fieldType, MappedFieldType defaultFieldType,

View File

@ -347,13 +347,9 @@ public final class FlatObjectFieldMapper extends DynamicKeyFieldMapper {
@Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
failIfNoDocValues();
return new KeyedFlatObjectFieldData.Builder(key);
return new KeyedFlatObjectFieldData.Builder(key, CoreValuesSourceType.BYTES);
}
@Override
public ValuesSourceType getValuesSourceType() {
return CoreValuesSourceType.BYTES;
}
}
/**
@ -386,6 +382,11 @@ public final class FlatObjectFieldMapper extends DynamicKeyFieldMapper {
return delegate.getFieldName();
}
@Override
public ValuesSourceType getValuesSourceType() {
return delegate.getValuesSourceType();
}
@Override
public SortField sortField(Object missingValue,
MultiValueMode sortMode,
@ -448,9 +449,11 @@ public final class FlatObjectFieldMapper extends DynamicKeyFieldMapper {
public static class Builder implements IndexFieldData.Builder {
private final String key;
private final ValuesSourceType valuesSourceType;
Builder(String key) {
Builder(String key, ValuesSourceType valuesSourceType) {
this.key = key;
this.valuesSourceType = valuesSourceType;
}
@Override
@ -461,7 +464,7 @@ public final class FlatObjectFieldMapper extends DynamicKeyFieldMapper {
MapperService mapperService) {
String fieldName = fieldType.name();
IndexOrdinalsFieldData delegate = new SortedSetOrdinalsIndexFieldData(indexSettings,
cache, fieldName, breakerService, AbstractLeafOrdinalsFieldData.DEFAULT_SCRIPT_FUNCTION);
cache, fieldName, valuesSourceType, breakerService, AbstractLeafOrdinalsFieldData.DEFAULT_SCRIPT_FUNCTION);
return new KeyedFlatObjectFieldData(key, delegate);
}
}
@ -537,13 +540,9 @@ public final class FlatObjectFieldMapper extends DynamicKeyFieldMapper {
@Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
failIfNoDocValues();
return new SortedSetOrdinalsIndexFieldData.Builder();
return new SortedSetOrdinalsIndexFieldData.Builder(CoreValuesSourceType.BYTES);
}
@Override
public ValuesSourceType getValuesSourceType() {
return CoreValuesSourceType.BYTES;
}
}
private FlatObjectFieldParser fieldParser;

View File

@ -35,6 +35,7 @@ import org.elasticsearch.index.mapper.TextFieldMapper;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.indices.breaker.CircuitBreakerService;
import org.elasticsearch.indices.breaker.NoneCircuitBreakerService;
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xpack.core.security.authz.accesscontrol.FieldSubsetReader;
import org.junit.After;
@ -61,8 +62,8 @@ public class FieldDataCacheWithFieldSubsetReaderTests extends ESTestCase {
String name = "_field";
indexFieldDataCache = new DummyAccountingFieldDataCache();
sortedSetOrdinalsIndexFieldData = new SortedSetOrdinalsIndexFieldData(indexSettings,indexFieldDataCache, name,
circuitBreakerService, AbstractLeafOrdinalsFieldData.DEFAULT_SCRIPT_FUNCTION);
pagedBytesIndexFieldData = new PagedBytesIndexFieldData(indexSettings, name, indexFieldDataCache,
CoreValuesSourceType.BYTES, circuitBreakerService, AbstractLeafOrdinalsFieldData.DEFAULT_SCRIPT_FUNCTION);
pagedBytesIndexFieldData = new PagedBytesIndexFieldData(indexSettings, name, CoreValuesSourceType.BYTES, indexFieldDataCache,
circuitBreakerService, TextFieldMapper.Defaults.FIELDDATA_MIN_FREQUENCY,
TextFieldMapper.Defaults.FIELDDATA_MAX_FREQUENCY,
TextFieldMapper.Defaults.FIELDDATA_MIN_SEGMENT_SIZE);

View File

@ -22,16 +22,19 @@ 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;
public abstract class AbstractLatLonShapeIndexFieldData implements IndexGeoShapeFieldData {
protected final Index index;
protected final String fieldName;
protected final ValuesSourceType valuesSourceType;
AbstractLatLonShapeIndexFieldData(Index index, String fieldName) {
AbstractLatLonShapeIndexFieldData(Index index, String fieldName, ValuesSourceType valuesSourceType) {
this.index = index;
this.fieldName = fieldName;
this.valuesSourceType = valuesSourceType;
}
@Override
@ -39,6 +42,11 @@ public abstract class AbstractLatLonShapeIndexFieldData implements IndexGeoShape
return fieldName;
}
@Override
public ValuesSourceType getValuesSourceType() {
return valuesSourceType;
}
@Override
public final void clear() {
// can't do
@ -56,8 +64,8 @@ public abstract class AbstractLatLonShapeIndexFieldData implements IndexGeoShape
}
public static class LatLonShapeIndexFieldData extends AbstractLatLonShapeIndexFieldData {
public LatLonShapeIndexFieldData(Index index, String fieldName) {
super(index, fieldName);
public LatLonShapeIndexFieldData(Index index, String fieldName, ValuesSourceType valuesSourceType) {
super(index, fieldName, valuesSourceType);
}
@Override
@ -95,11 +103,16 @@ public abstract class AbstractLatLonShapeIndexFieldData implements IndexGeoShape
}
public static class Builder implements IndexFieldData.Builder {
private final ValuesSourceType valuesSourceType;
public Builder(ValuesSourceType valuesSourceType) {
this.valuesSourceType = valuesSourceType;
}
@Override
public IndexFieldData<?> build(IndexSettings indexSettings, MappedFieldType fieldType, IndexFieldDataCache cache,
CircuitBreakerService breakerService, MapperService mapperService) {
// ignore breaker
return new LatLonShapeIndexFieldData(indexSettings.getIndex(), fieldType.name());
return new LatLonShapeIndexFieldData(indexSettings.getIndex(), fieldType.name(), valuesSourceType);
}
}
}

View File

@ -27,7 +27,6 @@ import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.index.mapper.ParseContext;
import org.elasticsearch.index.mapper.TypeParsers;
import org.elasticsearch.index.query.VectorGeoShapeQueryProcessor;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import org.elasticsearch.xpack.spatial.index.fielddata.AbstractLatLonShapeIndexFieldData;
import org.elasticsearch.xpack.spatial.index.fielddata.CentroidCalculator;
import org.elasticsearch.xpack.spatial.search.aggregations.support.GeoShapeValuesSourceType;
@ -146,12 +145,7 @@ public class GeoShapeWithDocValuesFieldMapper extends GeoShapeFieldMapper {
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
failIfNoDocValues();
return new AbstractLatLonShapeIndexFieldData.Builder();
}
@Override
public ValuesSourceType getValuesSourceType() {
return GeoShapeValuesSourceType.instance();
return new AbstractLatLonShapeIndexFieldData.Builder(GeoShapeValuesSourceType.instance());
}
@Override

View File

@ -14,6 +14,7 @@ import org.elasticsearch.search.aggregations.bucket.geogrid.GeoTileGridAggregati
import org.elasticsearch.search.aggregations.metrics.GeoCentroidAggregationBuilder;
import org.elasticsearch.search.aggregations.metrics.GeoCentroidAggregatorSupplier;
import org.elasticsearch.search.aggregations.metrics.GeoGridAggregatorSupplier;
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
import org.elasticsearch.search.aggregations.support.ValuesSourceRegistry;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.VersionUtils;
@ -35,7 +36,8 @@ public class SpatialPluginTests extends ESTestCase {
registrar.forEach(c -> c.accept(registryBuilder));
ValuesSourceRegistry registry = registryBuilder.build();
GeoCentroidAggregatorSupplier centroidSupplier = (GeoCentroidAggregatorSupplier) registry.getAggregator(
GeoShapeValuesSourceType.instance(), GeoCentroidAggregationBuilder.NAME);
new ValuesSourceConfig(GeoShapeValuesSourceType.instance(), null, false, null, null, null),
GeoCentroidAggregationBuilder.NAME);
if (License.OperationMode.TRIAL != operationMode &&
License.OperationMode.compare(operationMode, License.OperationMode.GOLD) < 0) {
ElasticsearchSecurityException exception = expectThrows(ElasticsearchSecurityException.class,
@ -55,7 +57,8 @@ public class SpatialPluginTests extends ESTestCase {
registrar.forEach(c -> c.accept(registryBuilder));
ValuesSourceRegistry registry = registryBuilder.build();
GeoGridAggregatorSupplier supplier = (GeoGridAggregatorSupplier) registry.getAggregator(
GeoShapeValuesSourceType.instance(), builderName);
new ValuesSourceConfig(GeoShapeValuesSourceType.instance(), null, false, null, null, null),
builderName);
if (License.OperationMode.TRIAL != operationMode &&
License.OperationMode.compare(operationMode, License.OperationMode.GOLD) < 0) {
ElasticsearchSecurityException exception = expectThrows(ElasticsearchSecurityException.class,

View File

@ -27,7 +27,6 @@ import org.elasticsearch.index.mapper.ParseContext;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import org.elasticsearch.xpack.vectors.query.VectorIndexFieldData;
import java.io.IOException;
@ -148,12 +147,7 @@ public class DenseVectorFieldMapper extends FieldMapper implements ArrayValueMap
@Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
return new VectorIndexFieldData.Builder(true);
}
@Override
public ValuesSourceType getValuesSourceType() {
return CoreValuesSourceType.BYTES;
return new VectorIndexFieldData.Builder(true, CoreValuesSourceType.BYTES);
}
@Override

View File

@ -25,6 +25,7 @@ import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.index.mapper.ParseContext;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
import org.elasticsearch.xpack.vectors.query.VectorIndexFieldData;
import java.io.IOException;
@ -118,7 +119,7 @@ public class SparseVectorFieldMapper extends FieldMapper {
@Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
return new VectorIndexFieldData.Builder(false);
return new VectorIndexFieldData.Builder(false, CoreValuesSourceType.BYTES);
}
@Override

View File

@ -21,6 +21,7 @@ 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;
@ -30,9 +31,11 @@ public class VectorIndexFieldData implements IndexFieldData<VectorDVLeafFieldDat
protected final Index index;
protected final String fieldName;
private final boolean isDense;
protected final ValuesSourceType valuesSourceType;
public VectorIndexFieldData(Index index, String fieldName, boolean isDense) {
public VectorIndexFieldData(Index index, String fieldName, boolean isDense, ValuesSourceType valuesSourceType) {
this.isDense = isDense;
this.valuesSourceType = valuesSourceType;
this.index = index;
this.fieldName = fieldName;
}
@ -42,6 +45,11 @@ public class VectorIndexFieldData implements IndexFieldData<VectorDVLeafFieldDat
return fieldName;
}
@Override
public ValuesSourceType getValuesSourceType() {
return valuesSourceType;
}
@Override
public final void clear() {
// can't do
@ -75,15 +83,17 @@ public class VectorIndexFieldData implements IndexFieldData<VectorDVLeafFieldDat
public static class Builder implements IndexFieldData.Builder {
private final boolean isDense;
public Builder(boolean isDense) {
private final ValuesSourceType valuesSourceType;
public Builder(boolean isDense, ValuesSourceType valuesSourceType) {
this.isDense = isDense;
this.valuesSourceType = valuesSourceType;
}
@Override
public IndexFieldData<?> build(IndexSettings indexSettings, MappedFieldType fieldType, IndexFieldDataCache cache,
CircuitBreakerService breakerService, MapperService mapperService) {
final String fieldName = fieldType.name();
return new VectorIndexFieldData(indexSettings.getIndex(), fieldName, isDense);
return new VectorIndexFieldData(indexSettings.getIndex(), fieldName, isDense, valuesSourceType);
}
}

View File

@ -806,21 +806,16 @@ public class WildcardFieldMapper extends FieldMapper {
@Override
public IndexFieldData<?> build(IndexSettings indexSettings, MappedFieldType fieldType, IndexFieldDataCache cache,
CircuitBreakerService breakerService, MapperService mapperService) {
return new WildcardBytesBinaryIndexFieldData(indexSettings.getIndex(), fieldType.name());
return new WildcardBytesBinaryIndexFieldData(indexSettings.getIndex(), fieldType.name(), CoreValuesSourceType.BYTES);
}};
}
@Override
public ValuesSourceType getValuesSourceType() {
return CoreValuesSourceType.BYTES;
}
}
static class WildcardBytesBinaryIndexFieldData extends BytesBinaryIndexFieldData {
WildcardBytesBinaryIndexFieldData(Index index, String fieldName) {
super(index, fieldName);
WildcardBytesBinaryIndexFieldData(Index index, String fieldName, ValuesSourceType valuesSourceType) {
super(index, fieldName, valuesSourceType);
}
@Override