From e50f5140921fe566e81840cb322b45d6332b3620 Mon Sep 17 00:00:00 2001 From: Mark Tozzi Date: Tue, 2 Jun 2020 12:16:53 -0400 Subject: [PATCH] IndexFieldData should hold the ValuesSourceType (#57373) (#57532) --- .../index/mapper/ScaledFloatFieldMapper.java | 11 +-- .../ChildrenAggregationBuilder.java | 3 +- .../join/mapper/MetaJoinFieldMapper.java | 8 +- .../join/mapper/ParentIdFieldMapper.java | 8 +- .../join/mapper/ParentJoinFieldMapper.java | 8 +- .../percolator/QueryBuilderStoreTests.java | 3 +- .../ICUCollationKeywordFieldMapper.java | 8 +- .../mapper/murmur3/Murmur3FieldMapper.java | 7 -- .../index/fielddata/IndexFieldData.java | 7 ++ .../fielddata/IndexHistogramFieldData.java | 10 +- .../fielddata/IndexNumericFieldData.java | 29 +++--- .../ordinals/GlobalOrdinalsBuilder.java | 4 +- .../GlobalOrdinalsIndexFieldData.java | 14 +++ .../plain/AbstractIndexFieldData.java | 17 +++- .../plain/AbstractIndexOrdinalsFieldData.java | 18 +++- .../AbstractLatLonPointIndexFieldData.java | 21 ++++- .../fielddata/plain/BinaryIndexFieldData.java | 18 +++- .../plain/BytesBinaryIndexFieldData.java | 17 +++- .../plain/ConstantIndexFieldData.java | 11 ++- .../plain/PagedBytesIndexFieldData.java | 26 ++++-- .../plain/SortedNumericIndexFieldData.java | 10 +- .../SortedSetOrdinalsIndexFieldData.java | 19 +++- .../index/mapper/BinaryFieldMapper.java | 8 +- .../index/mapper/BooleanFieldMapper.java | 7 -- .../index/mapper/DateFieldMapper.java | 7 -- .../index/mapper/GeoPointFieldMapper.java | 7 +- .../index/mapper/IdFieldMapper.java | 14 +-- .../index/mapper/IndexFieldMapper.java | 7 +- .../index/mapper/IpFieldMapper.java | 8 +- .../index/mapper/KeywordFieldMapper.java | 8 +- .../index/mapper/MappedFieldType.java | 11 --- .../index/mapper/NumberFieldMapper.java | 7 -- .../index/mapper/RangeFieldMapper.java | 8 +- .../index/mapper/SeqNoFieldMapper.java | 6 -- .../index/mapper/TextFieldMapper.java | 12 +-- .../index/mapper/TypeFieldMapper.java | 8 +- .../geogrid/GeoHashGridAggregatorFactory.java | 2 +- .../geogrid/GeoTileGridAggregatorFactory.java | 2 +- .../AutoDateHistogramAggregatorFactory.java | 2 +- .../DateHistogramAggregatorFactory.java | 2 +- .../histogram/HistogramAggregatorFactory.java | 2 +- .../missing/MissingAggregatorFactory.java | 12 ++- .../range/AbstractRangeAggregatorFactory.java | 3 +- .../range/BinaryRangeAggregatorFactory.java | 2 +- .../GeoDistanceRangeAggregatorFactory.java | 2 +- .../sampler/DiversifiedAggregatorFactory.java | 2 +- .../terms/RareTermsAggregatorFactory.java | 2 +- .../SignificantTermsAggregatorFactory.java | 2 +- .../bucket/terms/TermsAggregatorFactory.java | 2 +- .../metrics/AvgAggregatorFactory.java | 2 +- .../metrics/CardinalityAggregatorFactory.java | 2 +- .../ExtendedStatsAggregatorFactory.java | 18 ++-- .../metrics/GeoBoundsAggregatorFactory.java | 2 +- .../metrics/GeoCentroidAggregatorFactory.java | 2 +- .../metrics/MaxAggregatorFactory.java | 2 +- ...ianAbsoluteDeviationAggregatorFactory.java | 2 +- .../metrics/MinAggregatorFactory.java | 2 +- .../PercentileRanksAggregatorFactory.java | 2 +- .../metrics/PercentilesAggregatorFactory.java | 2 +- .../metrics/StatsAggregatorFactory.java | 2 +- .../metrics/SumAggregatorFactory.java | 2 +- .../metrics/ValueCountAggregatorFactory.java | 2 +- .../ValuesSourceAggregationBuilder.java | 5 + .../support/ValuesSourceConfig.java | 92 +++++++++++-------- .../support/ValuesSourceRegistry.java | 56 +++-------- .../aggregations/support/package-info.java | 77 ++++++++++++++++ .../index/fielddata/FieldDataCacheTests.java | 19 ++-- .../NoOrdinalsStringFieldDataTests.java | 6 ++ .../functionscore/FunctionScoreTests.java | 11 +++ .../aggregations/AggregatorTestCase.java | 10 +- .../boxplot/BoxplotAggregatorFactory.java | 2 +- .../mapper/HistogramFieldMapper.java | 8 +- .../StringStatsAggregatorFactory.java | 2 +- .../mapper/ConstantKeywordFieldMapper.java | 7 +- .../mapper/FlatObjectFieldMapper.java | 23 +++-- ...ldDataCacheWithFieldSubsetReaderTests.java | 5 +- .../AbstractLatLonShapeIndexFieldData.java | 21 ++++- .../GeoShapeWithDocValuesFieldMapper.java | 8 +- .../xpack/spatial/SpatialPluginTests.java | 7 +- .../mapper/DenseVectorFieldMapper.java | 8 +- .../mapper/SparseVectorFieldMapper.java | 3 +- .../vectors/query/VectorIndexFieldData.java | 16 +++- .../wildcard/mapper/WildcardFieldMapper.java | 13 +-- 83 files changed, 500 insertions(+), 373 deletions(-) create mode 100644 server/src/main/java/org/elasticsearch/search/aggregations/support/package-info.java diff --git a/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapper.java b/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapper.java index 89efba9d720..7f2214f903a 100644 --- a/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapper.java +++ b/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapper.java @@ -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); diff --git a/modules/parent-join/src/main/java/org/elasticsearch/join/aggregations/ChildrenAggregationBuilder.java b/modules/parent-join/src/main/java/org/elasticsearch/join/aggregations/ChildrenAggregationBuilder.java index 1e821f0a939..a7c62e1d89d 100644 --- a/modules/parent-join/src/main/java/org/elasticsearch/join/aggregations/ChildrenAggregationBuilder.java +++ b/modules/parent-join/src/main/java/org/elasticsearch/join/aggregations/ChildrenAggregationBuilder.java @@ -42,8 +42,7 @@ import java.io.IOException; import java.util.Map; import java.util.Objects; -public class ChildrenAggregationBuilder - extends ValuesSourceAggregationBuilder { +public class ChildrenAggregationBuilder extends ValuesSourceAggregationBuilder { public static final String NAME = "children"; diff --git a/modules/parent-join/src/main/java/org/elasticsearch/join/mapper/MetaJoinFieldMapper.java b/modules/parent-join/src/main/java/org/elasticsearch/join/mapper/MetaJoinFieldMapper.java index 3ab36babfb3..b259bb3d210 100644 --- a/modules/parent-join/src/main/java/org/elasticsearch/join/mapper/MetaJoinFieldMapper.java +++ b/modules/parent-join/src/main/java/org/elasticsearch/join/mapper/MetaJoinFieldMapper.java @@ -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 diff --git a/modules/parent-join/src/main/java/org/elasticsearch/join/mapper/ParentIdFieldMapper.java b/modules/parent-join/src/main/java/org/elasticsearch/join/mapper/ParentIdFieldMapper.java index 12e03c15ddc..cae435c2a18 100644 --- a/modules/parent-join/src/main/java/org/elasticsearch/join/mapper/ParentIdFieldMapper.java +++ b/modules/parent-join/src/main/java/org/elasticsearch/join/mapper/ParentIdFieldMapper.java @@ -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 diff --git a/modules/parent-join/src/main/java/org/elasticsearch/join/mapper/ParentJoinFieldMapper.java b/modules/parent-join/src/main/java/org/elasticsearch/join/mapper/ParentJoinFieldMapper.java index c7ebabcdc80..cb3872cf1e1 100644 --- a/modules/parent-join/src/main/java/org/elasticsearch/join/mapper/ParentJoinFieldMapper.java +++ b/modules/parent-join/src/main/java/org/elasticsearch/join/mapper/ParentJoinFieldMapper.java @@ -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 diff --git a/modules/percolator/src/test/java/org/elasticsearch/percolator/QueryBuilderStoreTests.java b/modules/percolator/src/test/java/org/elasticsearch/percolator/QueryBuilderStoreTests.java index 5964e1aac1c..2fd542748ce 100644 --- a/modules/percolator/src/test/java/org/elasticsearch/percolator/QueryBuilderStoreTests.java +++ b/modules/percolator/src/test/java/org/elasticsearch/percolator/QueryBuilderStoreTests.java @@ -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(); diff --git a/plugins/analysis-icu/src/main/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapper.java b/plugins/analysis-icu/src/main/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapper.java index 2e93ff99a2a..dca847e3d7e 100644 --- a/plugins/analysis-icu/src/main/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapper.java +++ b/plugins/analysis-icu/src/main/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapper.java @@ -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 diff --git a/plugins/mapper-murmur3/src/main/java/org/elasticsearch/index/mapper/murmur3/Murmur3FieldMapper.java b/plugins/mapper-murmur3/src/main/java/org/elasticsearch/index/mapper/murmur3/Murmur3FieldMapper.java index a8a51176142..2815c108de0 100644 --- a/plugins/mapper-murmur3/src/main/java/org/elasticsearch/index/mapper/murmur3/Murmur3FieldMapper.java +++ b/plugins/mapper-murmur3/src/main/java/org/elasticsearch/index/mapper/murmur3/Murmur3FieldMapper.java @@ -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()); diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/IndexFieldData.java b/server/src/main/java/org/elasticsearch/index/fielddata/IndexFieldData.java index 82634dffa43..93d8ab8d1e4 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/IndexFieldData.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/IndexFieldData.java @@ -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 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. */ diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/IndexHistogramFieldData.java b/server/src/main/java/org/elasticsearch/index/fielddata/IndexHistogramFieldData.java index dd0b2817365..d8ba10acd9b 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/IndexHistogramFieldData.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/IndexHistogramFieldData.java @@ -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 { 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> 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"); diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/plain/AbstractIndexFieldData.java b/server/src/main/java/org/elasticsearch/index/fielddata/plain/AbstractIndexFieldData.java index 023c0a248a0..c5dd33626f9 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/plain/AbstractIndexFieldData.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/plain/AbstractIndexFieldData.java @@ -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 extends AbstractIndexComponent implements IndexFieldData { 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 extends A return this.fieldName; } + @Override + public ValuesSourceType getValuesSourceType() { + return valuesSourceType; + } + @Override public void clear() { cache.clear(fieldName); diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/plain/AbstractIndexOrdinalsFieldData.java b/server/src/main/java/org/elasticsearch/index/fielddata/plain/AbstractIndexOrdinalsFieldData.java index 3d549c82b82..9ed37b09f7b 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/plain/AbstractIndexOrdinalsFieldData.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/plain/AbstractIndexOrdinalsFieldData.java @@ -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; diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/plain/AbstractLatLonPointIndexFieldData.java b/server/src/main/java/org/elasticsearch/index/fielddata/plain/AbstractLatLonPointIndexFieldData.java index a8eaef2c57d..86e0aab89c7 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/plain/AbstractLatLonPointIndexFieldData.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/plain/AbstractLatLonPointIndexFieldData.java @@ -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); } } } diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/plain/BinaryIndexFieldData.java b/server/src/main/java/org/elasticsearch/index/fielddata/plain/BinaryIndexFieldData.java index aeff6800d37..714b703635e 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/plain/BinaryIndexFieldData.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/plain/BinaryIndexFieldData.java @@ -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 { 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 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); } } diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/plain/ConstantIndexFieldData.java b/server/src/main/java/org/elasticsearch/index/fielddata/plain/ConstantIndexFieldData.java index 81a87ad8465..e4ebbd63f32 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/plain/ConstantIndexFieldData.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/plain/ConstantIndexFieldData.java @@ -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 valueFunction; + private final ValuesSourceType valuesSourceType; - public Builder(Function valueFunction) { + public Builder(Function 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); diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/plain/PagedBytesIndexFieldData.java b/server/src/main/java/org/elasticsearch/index/fielddata/plain/PagedBytesIndexFieldData.java index 5017745cf95..c31546e3b7b 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/plain/PagedBytesIndexFieldData.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/plain/PagedBytesIndexFieldData.java @@ -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 diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/plain/SortedNumericIndexFieldData.java b/server/src/main/java/org/elasticsearch/index/fielddata/plain/SortedNumericIndexFieldData.java index b7d44e1d868..e4898c790c6 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/plain/SortedNumericIndexFieldData.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/plain/SortedNumericIndexFieldData.java @@ -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 @@ -115,7 +123,7 @@ public class SortedNumericIndexFieldData extends IndexNumericFieldData { } return new LongValuesComparatorSource(this, missingValue, sortMode, nested); } - + @Override protected XFieldComparatorSource dateNanosComparatorSource(Object missingValue, MultiValueMode sortMode, Nested nested) { if (numericType == NumericType.DATE) { diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/plain/SortedSetOrdinalsIndexFieldData.java b/server/src/main/java/org/elasticsearch/index/fielddata/plain/SortedSetOrdinalsIndexFieldData.java index 4441b9758a9..5b18e6fa91e 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/plain/SortedSetOrdinalsIndexFieldData.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/plain/SortedSetOrdinalsIndexFieldData.java @@ -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> 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> scriptFunction) { + public Builder(Function> 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> 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> 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 diff --git a/server/src/main/java/org/elasticsearch/index/mapper/BinaryFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/BinaryFieldMapper.java index c63a8c46fd7..1419aebcd8f 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/BinaryFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/BinaryFieldMapper.java @@ -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 diff --git a/server/src/main/java/org/elasticsearch/index/mapper/BooleanFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/BooleanFieldMapper.java index 09c9ac3aa56..44f9ffbf421 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/BooleanFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/BooleanFieldMapper.java @@ -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) { diff --git a/server/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java index 971be416698..6648d2f776c 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java @@ -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; diff --git a/server/src/main/java/org/elasticsearch/index/mapper/GeoPointFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/GeoPointFieldMapper.java index 60a48947da0..00c7c63392d 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/GeoPointFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/GeoPointFieldMapper.java @@ -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 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)); diff --git a/server/src/main/java/org/elasticsearch/index/mapper/IndexFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/IndexFieldMapper.java index e2954b2419d..7f9465b14ef 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/IndexFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/IndexFieldMapper.java @@ -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) { diff --git a/server/src/main/java/org/elasticsearch/index/mapper/IpFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/IpFieldMapper.java index e60638d0734..d1466103b3a 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/IpFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/IpFieldMapper.java @@ -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 diff --git a/server/src/main/java/org/elasticsearch/index/mapper/KeywordFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/KeywordFieldMapper.java index 115bab34654..8218fc1be4b 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/KeywordFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/KeywordFieldMapper.java @@ -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 diff --git a/server/src/main/java/org/elasticsearch/index/mapper/MappedFieldType.java b/server/src/main/java/org/elasticsearch/index/mapper/MappedFieldType.java index 0321fd81ede..3d2072311b6 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/MappedFieldType.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/MappedFieldType.java @@ -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; diff --git a/server/src/main/java/org/elasticsearch/index/mapper/NumberFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/NumberFieldMapper.java index 34560a6587f..6899c8308bb 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/NumberFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/NumberFieldMapper.java @@ -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) { diff --git a/server/src/main/java/org/elasticsearch/index/mapper/RangeFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/RangeFieldMapper.java index d46becc75f9..ef9b19ec7d0 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/RangeFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/RangeFieldMapper.java @@ -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 diff --git a/server/src/main/java/org/elasticsearch/index/mapper/SeqNoFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/SeqNoFieldMapper.java index c53133175f1..c4751bc8245 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/SeqNoFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/SeqNoFieldMapper.java @@ -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) { diff --git a/server/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java index db6c54b1d7a..80bb9af5de3 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java @@ -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; diff --git a/server/src/main/java/org/elasticsearch/index/mapper/TypeFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/TypeFieldMapper.java index 3eccd29ff63..5ecff3b6faf 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/TypeFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/TypeFieldMapper.java @@ -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 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 diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoHashGridAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoHashGridAggregatorFactory.java index 51acc2c7d49..d2573c4b80c 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoHashGridAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoHashGridAggregatorFactory.java @@ -80,7 +80,7 @@ public class GeoHashGridAggregatorFactory extends ValuesSourceAggregatorFactory boolean collectsFromSingleBucket, Map 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() + "]"); diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoTileGridAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoTileGridAggregatorFactory.java index 1b42a1d84be..d7898949a4a 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoTileGridAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoTileGridAggregatorFactory.java @@ -78,7 +78,7 @@ public class GeoTileGridAggregatorFactory extends ValuesSourceAggregatorFactory boolean collectsFromSingleBucket, Map 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() + "]"); diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/AutoDateHistogramAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/AutoDateHistogramAggregatorFactory.java index 747df2d3ec9..f81d7afcd51 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/AutoDateHistogramAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/AutoDateHistogramAggregatorFactory.java @@ -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 [" + diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramAggregatorFactory.java index 81730e1e00f..010605fc62c 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramAggregatorFactory.java @@ -81,7 +81,7 @@ public final class DateHistogramAggregatorFactory extends ValuesSourceAggregator Aggregator parent, boolean collectsFromSingleBucket, Map 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 [" + diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/HistogramAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/HistogramAggregatorFactory.java index 6b9263a7af2..adc48559833 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/HistogramAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/HistogramAggregatorFactory.java @@ -92,7 +92,7 @@ public final class HistogramAggregatorFactory extends ValuesSourceAggregatorFact Aggregator parent, boolean collectsFromSingleBucket, Map 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 [" + diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/missing/MissingAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/missing/MissingAggregatorFactory.java index a3a8dc8145d..d25616a9fcd 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/missing/MissingAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/missing/MissingAggregatorFactory.java @@ -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 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); } } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/AbstractRangeAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/AbstractRangeAggregatorFactory.java index 2e75903d615..1c3126dd027 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/AbstractRangeAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/AbstractRangeAggregatorFactory.java @@ -82,7 +82,8 @@ public class AbstractRangeAggregatorFactory extends ValuesSourc Aggregator parent, boolean collectsFromSingleBucket, Map 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 [" + diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/BinaryRangeAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/BinaryRangeAggregatorFactory.java index 84f2b8def05..899a5d52d33 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/BinaryRangeAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/BinaryRangeAggregatorFactory.java @@ -66,7 +66,7 @@ public class BinaryRangeAggregatorFactory extends ValuesSourceAggregatorFactory SearchContext searchContext, Aggregator parent, boolean collectsFromSingleBucket, Map metadata) throws IOException { - AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config.valueSourceType(), + AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config, IpRangeAggregationBuilder.NAME); if (aggregatorSupplier instanceof IpRangeAggregatorSupplier == false) { diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/GeoDistanceRangeAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/GeoDistanceRangeAggregatorFactory.java index 8f027bb5ae1..9ce75af7fed 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/GeoDistanceRangeAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/GeoDistanceRangeAggregatorFactory.java @@ -91,7 +91,7 @@ public class GeoDistanceRangeAggregatorFactory extends ValuesSourceAggregatorFac boolean collectsFromSingleBucket, Map 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() + "]"); diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/DiversifiedAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/DiversifiedAggregatorFactory.java index a3a406a6d27..34dfa1df4c5 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/DiversifiedAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/DiversifiedAggregatorFactory.java @@ -94,7 +94,7 @@ public class DiversifiedAggregatorFactory extends ValuesSourceAggregatorFactory boolean collectsFromSingleBucket, Map 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() + diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/RareTermsAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/RareTermsAggregatorFactory.java index 4a69df3a06c..373f4f547ea 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/RareTermsAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/RareTermsAggregatorFactory.java @@ -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 [" + diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/SignificantTermsAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/SignificantTermsAggregatorFactory.java index e89ce4d265c..f4dd81614d8 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/SignificantTermsAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/SignificantTermsAggregatorFactory.java @@ -300,7 +300,7 @@ public class SignificantTermsAggregatorFactory extends ValuesSourceAggregatorFac Aggregator parent, boolean collectsFromSingleBucket, Map 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 [" + diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/TermsAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/TermsAggregatorFactory.java index 955ed241679..62953e229b5 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/TermsAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/TermsAggregatorFactory.java @@ -240,7 +240,7 @@ public class TermsAggregatorFactory extends ValuesSourceAggregatorFactory { Aggregator parent, boolean collectsFromSingleBucket, Map 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 [" + diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/AvgAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/AvgAggregatorFactory.java index c7d86ae1c35..b016df14179 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/AvgAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/AvgAggregatorFactory.java @@ -63,7 +63,7 @@ class AvgAggregatorFactory extends ValuesSourceAggregatorFactory { Aggregator parent, boolean collectsFromSingleBucket, Map metadata) throws IOException { - AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config.valueSourceType(), + AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config, AvgAggregationBuilder.NAME); if (aggregatorSupplier instanceof MetricAggregatorSupplier == false) { diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/CardinalityAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/CardinalityAggregatorFactory.java index 7e7becacfea..044b7aa69c7 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/CardinalityAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/CardinalityAggregatorFactory.java @@ -67,7 +67,7 @@ class CardinalityAggregatorFactory extends ValuesSourceAggregatorFactory { Aggregator parent, boolean collectsFromSingleBucket, Map 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 [" + diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/ExtendedStatsAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/ExtendedStatsAggregatorFactory.java index be921a12cd2..b74cf21a7ce 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/ExtendedStatsAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/ExtendedStatsAggregatorFactory.java @@ -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; @@ -66,13 +67,16 @@ class ExtendedStatsAggregatorFactory extends ValuesSourceAggregatorFactory { @Override protected Aggregator doCreateInternal(ValuesSource valuesSource, - SearchContext searchContext, - Aggregator parent, - boolean collectsFromSingleBucket, - Map metadata) throws IOException { - if (valuesSource instanceof Numeric == false) { - throw new AggregationExecutionException("ValuesSource type " + valuesSource.toString() + "is not supported for aggregation " + - this.name()); + SearchContext searchContext, + Aggregator parent, + boolean collectsFromSingleBucket, + Map metadata) throws IOException { + 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); diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/GeoBoundsAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/GeoBoundsAggregatorFactory.java index 91d61ab6962..b4148ef4770 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/GeoBoundsAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/GeoBoundsAggregatorFactory.java @@ -64,7 +64,7 @@ class GeoBoundsAggregatorFactory extends ValuesSourceAggregatorFactory { boolean collectsFromSingleBucket, Map 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 " diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/GeoCentroidAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/GeoCentroidAggregatorFactory.java index 156fa4140bf..27a1be909aa 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/GeoCentroidAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/GeoCentroidAggregatorFactory.java @@ -60,7 +60,7 @@ class GeoCentroidAggregatorFactory extends ValuesSourceAggregatorFactory { boolean collectsFromSingleBucket, Map 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 " diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/MaxAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/MaxAggregatorFactory.java index e1a3477ee0a..64a6cca392f 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/MaxAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/MaxAggregatorFactory.java @@ -62,7 +62,7 @@ class MaxAggregatorFactory extends ValuesSourceAggregatorFactory { Aggregator parent, boolean collectsFromSingleBucket, Map metadata) throws IOException { - AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config.valueSourceType(), + AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config, MaxAggregationBuilder.NAME); if (aggregatorSupplier instanceof MetricAggregatorSupplier == false) { diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/MedianAbsoluteDeviationAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/MedianAbsoluteDeviationAggregatorFactory.java index 6acdf7eb853..0822ece7fc2 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/MedianAbsoluteDeviationAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/MedianAbsoluteDeviationAggregatorFactory.java @@ -78,7 +78,7 @@ public class MedianAbsoluteDeviationAggregatorFactory extends ValuesSourceAggreg Aggregator parent, boolean collectsFromSingleBucket, Map metadata) throws IOException { - AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config.valueSourceType(), + AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config, MedianAbsoluteDeviationAggregationBuilder.NAME); if (aggregatorSupplier instanceof MedianAbsoluteDeviationAggregatorSupplier == false) { diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/MinAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/MinAggregatorFactory.java index bb1a96edb40..b9158dbefae 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/MinAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/MinAggregatorFactory.java @@ -62,7 +62,7 @@ class MinAggregatorFactory extends ValuesSourceAggregatorFactory { Aggregator parent, boolean collectsFromSingleBucket, Map metadata) throws IOException { - AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config.valueSourceType(), + AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config, MinAggregationBuilder.NAME); if (aggregatorSupplier instanceof MetricAggregatorSupplier == false) { diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/PercentileRanksAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/PercentileRanksAggregatorFactory.java index d1045a5f1d5..97e0c45c227 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/PercentileRanksAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/PercentileRanksAggregatorFactory.java @@ -89,7 +89,7 @@ class PercentileRanksAggregatorFactory extends ValuesSourceAggregatorFactory { Aggregator parent, boolean collectsFromSingleBucket, Map metadata) throws IOException { - AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config.valueSourceType(), + AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config, PercentileRanksAggregationBuilder.NAME); if (aggregatorSupplier instanceof PercentilesAggregatorSupplier == false) { diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/PercentilesAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/PercentilesAggregatorFactory.java index e7ff389baa6..ef4dbf5f7ec 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/PercentilesAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/PercentilesAggregatorFactory.java @@ -89,7 +89,7 @@ class PercentilesAggregatorFactory extends ValuesSourceAggregatorFactory { boolean collectsFromSingleBucket, Map metadata) throws IOException { - AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config.valueSourceType(), + AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config, PercentilesAggregationBuilder.NAME); if (aggregatorSupplier instanceof PercentilesAggregatorSupplier == false) { diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/StatsAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/StatsAggregatorFactory.java index c9a921f3a64..d0484d5ad05 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/StatsAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/StatsAggregatorFactory.java @@ -65,7 +65,7 @@ class StatsAggregatorFactory extends ValuesSourceAggregatorFactory { Aggregator parent, boolean collectsFromSingleBucket, Map metadata) throws IOException { - AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config.valueSourceType(), + AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config, StatsAggregationBuilder.NAME); if (aggregatorSupplier instanceof MetricAggregatorSupplier == false) { diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/SumAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/SumAggregatorFactory.java index 6bdc08b211c..de182467939 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/SumAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/SumAggregatorFactory.java @@ -66,7 +66,7 @@ class SumAggregatorFactory extends ValuesSourceAggregatorFactory { Aggregator parent, boolean collectsFromSingleBucket, Map metadata) throws IOException { - AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config.valueSourceType(), + AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config, SumAggregationBuilder.NAME); if (aggregatorSupplier instanceof MetricAggregatorSupplier == false) { diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/ValueCountAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/ValueCountAggregatorFactory.java index 3686a9161c5..367d299dc1a 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/ValueCountAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/ValueCountAggregatorFactory.java @@ -61,7 +61,7 @@ class ValueCountAggregatorFactory extends ValuesSourceAggregatorFactory { Aggregator parent, boolean collectsFromSingleBucket, Map 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 [" + diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceAggregationBuilder.java b/server/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceAggregationBuilder.java index 780a51c56ae..db363d16016 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceAggregationBuilder.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceAggregationBuilder.java @@ -346,6 +346,11 @@ public abstract class ValuesSourceAggregationBuilder indexFieldData = context.getForField(fieldType); - return context.getValuesSourceRegistry().getValuesSourceType(fieldType, aggregationName, indexFieldData, - userValueTypeHint, defaultValuesSourceType); + FieldContext fieldContext, + ValueType userValueTypeHint, + ValuesSourceType defaultValuesSourceType + ) { + return fieldContext.indexFieldData().getValuesSourceType(); } private static ValuesSourceType getLegacyMapping( - QueryShardContext context, - MappedFieldType fieldType, - String aggregationName, - ValueType userValueTypeHint, - ValuesSourceType defaultValuesSourceType) { - IndexFieldData indexFieldData = context.getForField(fieldType); + FieldContext fieldContext, + ValueType userValueTypeHint, + 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, - boolean unmapped, - AggregationScript.LeafFactory script, - ValueType scriptValueType, - QueryShardContext queryShardContext) { - if (unmapped && fieldType != null) { + public ValuesSourceConfig( + ValuesSourceType valuesSourceType, + FieldContext fieldContext, + boolean unmapped, + AggregationScript.LeafFactory script, + ValueType scriptValueType, + 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; } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceRegistry.java b/server/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceRegistry.java index 0f40563cee8..fba3eda254d 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceRegistry.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceRegistry.java @@ -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) { + 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(valuesSourceType, aggregatorRegistry.get(aggregationName)); + AggregatorSupplier supplier = findMatchingSuppier( + valuesSourceConfig.valueSourceType(), + aggregatorRegistry.get(aggregationName) + ); if (supplier == null) { - throw new AggregationExecutionException("ValuesSource type " + valuesSourceType.toString() + - " is not supported for aggregation" + aggregationName); - } + // 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; } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/support/package-info.java b/server/src/main/java/org/elasticsearch/search/aggregations/support/package-info.java new file mode 100644 index 00000000000..a77bbca9186 --- /dev/null +++ b/server/src/main/java/org/elasticsearch/search/aggregations/support/package-info.java @@ -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; + +/** + *

+ * This package holds shared code for the aggregations framework, especially around dealing with values. + *

+ * + *

Key Classes

+ * + *

{@link org.elasticsearch.search.aggregations.support.ValuesSource} and its subclasses

+ *

+ * 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). + *

+ * + *

{@link org.elasticsearch.search.aggregations.support.ValuesSourceRegistry}

+ *

+ * 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. + *

+ * + *

{@link org.elasticsearch.search.aggregations.support.ValuesSourceType}

+ *

+ * 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. + *

+ * + *

{@link org.elasticsearch.search.aggregations.support.ValuesSourceConfig}

+ *

+ * 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. + *

+ * + *

+ * 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. + *

+ * + *

Classes we are trying to phase out

+ *

{@link org.elasticsearch.search.aggregations.support.ValueType}

+ *

+ * 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. + *

+ * + */ diff --git a/server/src/test/java/org/elasticsearch/index/fielddata/FieldDataCacheTests.java b/server/src/test/java/org/elasticsearch/index/fielddata/FieldDataCacheTests.java index e47a8de2d88..c5c97b615dd 100644 --- a/server/src/test/java/org/elasticsearch/index/fielddata/FieldDataCacheTests.java +++ b/server/src/test/java/org/elasticsearch/index/fielddata/FieldDataCacheTests.java @@ -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(), - TextFieldMapper.Defaults.FIELDDATA_MIN_FREQUENCY, - TextFieldMapper.Defaults.FIELDDATA_MAX_FREQUENCY, - TextFieldMapper.Defaults.FIELDDATA_MIN_SEGMENT_SIZE); + 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 + ); } private IndexSettings createIndexSettings() { diff --git a/server/src/test/java/org/elasticsearch/index/fielddata/NoOrdinalsStringFieldDataTests.java b/server/src/test/java/org/elasticsearch/index/fielddata/NoOrdinalsStringFieldDataTests.java index be3dde6e56b..d1c9f609957 100644 --- a/server/src/test/java/org/elasticsearch/index/fielddata/NoOrdinalsStringFieldDataTests.java +++ b/server/src/test/java/org/elasticsearch/index/fielddata/NoOrdinalsStringFieldDataTests.java @@ -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); diff --git a/server/src/test/java/org/elasticsearch/index/query/functionscore/FunctionScoreTests.java b/server/src/test/java/org/elasticsearch/index/query/functionscore/FunctionScoreTests.java index b93bf308e75..3ea06bc9daa 100644 --- a/server/src/test/java/org/elasticsearch/index/query/functionscore/FunctionScoreTests.java +++ b/server/src/test/java/org/elasticsearch/index/query/functionscore/FunctionScoreTests.java @@ -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() { diff --git a/test/framework/src/main/java/org/elasticsearch/search/aggregations/AggregatorTestCase.java b/test/framework/src/main/java/org/elasticsearch/search/aggregations/AggregatorTestCase.java index 2ebb6fc84ac..4cedf071b25 100644 --- a/test/framework/src/main/java/org/elasticsearch/search/aggregations/AggregatorTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/search/aggregations/AggregatorTestCase.java @@ -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; diff --git a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/boxplot/BoxplotAggregatorFactory.java b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/boxplot/BoxplotAggregatorFactory.java index f8a47b23ff5..c9819b032fb 100644 --- a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/boxplot/BoxplotAggregatorFactory.java +++ b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/boxplot/BoxplotAggregatorFactory.java @@ -59,7 +59,7 @@ public class BoxplotAggregatorFactory extends ValuesSourceAggregatorFactory { Aggregator parent, boolean collectsFromSingleBucket, Map metadata) throws IOException { - AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config.valueSourceType(), + AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config, BoxplotAggregationBuilder.NAME); if (aggregatorSupplier instanceof BoxplotAggregatorSupplier == false) { diff --git a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/mapper/HistogramFieldMapper.java b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/mapper/HistogramFieldMapper.java index ae85f3a7d07..5423bd4a8c5 100644 --- a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/mapper/HistogramFieldMapper.java +++ b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/mapper/HistogramFieldMapper.java @@ -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()) { diff --git a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/stringstats/StringStatsAggregatorFactory.java b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/stringstats/StringStatsAggregatorFactory.java index 1ae7e8168c1..a79b1c3dbfa 100644 --- a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/stringstats/StringStatsAggregatorFactory.java +++ b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/stringstats/StringStatsAggregatorFactory.java @@ -53,7 +53,7 @@ class StringStatsAggregatorFactory extends ValuesSourceAggregatorFactory { Aggregator parent, boolean collectsFromSingleBucket, Map metadata) throws IOException { - AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config.valueSourceType(), + AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config, StringStatsAggregationBuilder.NAME); if (aggregatorSupplier instanceof StringStatsAggregatorSupplier == false) { diff --git a/x-pack/plugin/mapper-constant-keyword/src/main/java/org/elasticsearch/xpack/constantkeyword/mapper/ConstantKeywordFieldMapper.java b/x-pack/plugin/mapper-constant-keyword/src/main/java/org/elasticsearch/xpack/constantkeyword/mapper/ConstantKeywordFieldMapper.java index 1efb8c10bf2..635ec9a181a 100644 --- a/x-pack/plugin/mapper-constant-keyword/src/main/java/org/elasticsearch/xpack/constantkeyword/mapper/ConstantKeywordFieldMapper.java +++ b/x-pack/plugin/mapper-constant-keyword/src/main/java/org/elasticsearch/xpack/constantkeyword/mapper/ConstantKeywordFieldMapper.java @@ -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, diff --git a/x-pack/plugin/mapper-flattened/src/main/java/org/elasticsearch/xpack/flattened/mapper/FlatObjectFieldMapper.java b/x-pack/plugin/mapper-flattened/src/main/java/org/elasticsearch/xpack/flattened/mapper/FlatObjectFieldMapper.java index 6c01804c82d..45f67688bf8 100644 --- a/x-pack/plugin/mapper-flattened/src/main/java/org/elasticsearch/xpack/flattened/mapper/FlatObjectFieldMapper.java +++ b/x-pack/plugin/mapper-flattened/src/main/java/org/elasticsearch/xpack/flattened/mapper/FlatObjectFieldMapper.java @@ -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; diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/accesscontrol/FieldDataCacheWithFieldSubsetReaderTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/accesscontrol/FieldDataCacheWithFieldSubsetReaderTests.java index be36b44da4f..bbf26360e6c 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/accesscontrol/FieldDataCacheWithFieldSubsetReaderTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/accesscontrol/FieldDataCacheWithFieldSubsetReaderTests.java @@ -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); diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/AbstractLatLonShapeIndexFieldData.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/AbstractLatLonShapeIndexFieldData.java index 14d1b3a4219..7f91b1d59da 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/AbstractLatLonShapeIndexFieldData.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/AbstractLatLonShapeIndexFieldData.java @@ -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); } } } diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/GeoShapeWithDocValuesFieldMapper.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/GeoShapeWithDocValuesFieldMapper.java index 830bff751d3..ac05f5acfbd 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/GeoShapeWithDocValuesFieldMapper.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/GeoShapeWithDocValuesFieldMapper.java @@ -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 diff --git a/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/SpatialPluginTests.java b/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/SpatialPluginTests.java index 48627150876..9a836efa5b5 100644 --- a/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/SpatialPluginTests.java +++ b/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/SpatialPluginTests.java @@ -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, diff --git a/x-pack/plugin/vectors/src/main/java/org/elasticsearch/xpack/vectors/mapper/DenseVectorFieldMapper.java b/x-pack/plugin/vectors/src/main/java/org/elasticsearch/xpack/vectors/mapper/DenseVectorFieldMapper.java index fb076170a1f..95e08d943fe 100644 --- a/x-pack/plugin/vectors/src/main/java/org/elasticsearch/xpack/vectors/mapper/DenseVectorFieldMapper.java +++ b/x-pack/plugin/vectors/src/main/java/org/elasticsearch/xpack/vectors/mapper/DenseVectorFieldMapper.java @@ -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 diff --git a/x-pack/plugin/vectors/src/main/java/org/elasticsearch/xpack/vectors/mapper/SparseVectorFieldMapper.java b/x-pack/plugin/vectors/src/main/java/org/elasticsearch/xpack/vectors/mapper/SparseVectorFieldMapper.java index 42bef3439b0..78bb9809538 100644 --- a/x-pack/plugin/vectors/src/main/java/org/elasticsearch/xpack/vectors/mapper/SparseVectorFieldMapper.java +++ b/x-pack/plugin/vectors/src/main/java/org/elasticsearch/xpack/vectors/mapper/SparseVectorFieldMapper.java @@ -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 diff --git a/x-pack/plugin/vectors/src/main/java/org/elasticsearch/xpack/vectors/query/VectorIndexFieldData.java b/x-pack/plugin/vectors/src/main/java/org/elasticsearch/xpack/vectors/query/VectorIndexFieldData.java index 598c775a7da..b31cf083f4d 100644 --- a/x-pack/plugin/vectors/src/main/java/org/elasticsearch/xpack/vectors/query/VectorIndexFieldData.java +++ b/x-pack/plugin/vectors/src/main/java/org/elasticsearch/xpack/vectors/query/VectorIndexFieldData.java @@ -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 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); } } diff --git a/x-pack/plugin/wildcard/src/main/java/org/elasticsearch/xpack/wildcard/mapper/WildcardFieldMapper.java b/x-pack/plugin/wildcard/src/main/java/org/elasticsearch/xpack/wildcard/mapper/WildcardFieldMapper.java index cde3d7d0772..b279a693855 100644 --- a/x-pack/plugin/wildcard/src/main/java/org/elasticsearch/xpack/wildcard/mapper/WildcardFieldMapper.java +++ b/x-pack/plugin/wildcard/src/main/java/org/elasticsearch/xpack/wildcard/mapper/WildcardFieldMapper.java @@ -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