diff --git a/modules/aggs-matrix-stats/src/main/java/org/elasticsearch/search/aggregations/support/ArrayValuesSourceAggregatorFactory.java b/modules/aggs-matrix-stats/src/main/java/org/elasticsearch/search/aggregations/support/ArrayValuesSourceAggregatorFactory.java index 1186aff415c63..d1124c9e693a5 100644 --- a/modules/aggs-matrix-stats/src/main/java/org/elasticsearch/search/aggregations/support/ArrayValuesSourceAggregatorFactory.java +++ b/modules/aggs-matrix-stats/src/main/java/org/elasticsearch/search/aggregations/support/ArrayValuesSourceAggregatorFactory.java @@ -53,7 +53,7 @@ public Aggregator createInternal(SearchContext searchContext, HashMap valuesSources = new HashMap<>(); for (Map.Entry config : configs.entrySet()) { - ValuesSource vs = config.getValue().toValuesSource(queryShardContext); + ValuesSource vs = config.getValue().toValuesSource(); if (vs != null) { valuesSources.put(config.getKey(), vs); } 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 5d6c7d6dd1187..8eedf429fa5d7 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 @@ -25,7 +25,6 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.index.fielddata.plain.SortedSetDVOrdinalsIndexFieldData; import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.query.QueryShardContext; import org.elasticsearch.join.mapper.ParentIdFieldMapper; @@ -34,7 +33,6 @@ import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.support.CoreValuesSourceType; -import org.elasticsearch.search.aggregations.support.FieldContext; import org.elasticsearch.search.aggregations.support.ValuesSourceAggregationBuilder; import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory; import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; @@ -109,23 +107,19 @@ protected ValuesSourceAggregatorFactory innerBuild(QueryShardContext queryShardC @Override protected ValuesSourceConfig resolveConfig(QueryShardContext queryShardContext) { - ValuesSourceConfig config = new ValuesSourceConfig(CoreValuesSourceType.BYTES); - joinFieldResolveConfig(queryShardContext, config); - return config; - } - - private void joinFieldResolveConfig(QueryShardContext queryShardContext, ValuesSourceConfig config) { + ValuesSourceConfig config; ParentJoinFieldMapper parentJoinFieldMapper = ParentJoinFieldMapper.getMapper(queryShardContext.getMapperService()); ParentIdFieldMapper parentIdFieldMapper = parentJoinFieldMapper.getParentIdFieldMapper(childType, false); if (parentIdFieldMapper != null) { parentFilter = parentIdFieldMapper.getParentFilter(); childFilter = parentIdFieldMapper.getChildFilter(childType); MappedFieldType fieldType = parentIdFieldMapper.fieldType(); - final SortedSetDVOrdinalsIndexFieldData fieldData = queryShardContext.getForField(fieldType); - config.fieldContext(new FieldContext(fieldType.name(), fieldData, fieldType)); + config = ValuesSourceConfig.resolveFieldOnly(fieldType, queryShardContext); } else { - config.unmapped(true); + // Unmapped field case + config = ValuesSourceConfig.resolveUnmapped(defaultValueSourceType(), queryShardContext); } + return config; } @Override diff --git a/modules/parent-join/src/main/java/org/elasticsearch/join/aggregations/ParentAggregationBuilder.java b/modules/parent-join/src/main/java/org/elasticsearch/join/aggregations/ParentAggregationBuilder.java index 5b7116d551d45..f920965e178cd 100644 --- a/modules/parent-join/src/main/java/org/elasticsearch/join/aggregations/ParentAggregationBuilder.java +++ b/modules/parent-join/src/main/java/org/elasticsearch/join/aggregations/ParentAggregationBuilder.java @@ -25,7 +25,6 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.index.fielddata.plain.SortedSetDVOrdinalsIndexFieldData; import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.query.QueryShardContext; import org.elasticsearch.join.mapper.ParentIdFieldMapper; @@ -34,7 +33,6 @@ import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.support.CoreValuesSourceType; -import org.elasticsearch.search.aggregations.support.FieldContext; import org.elasticsearch.search.aggregations.support.ValuesSourceAggregationBuilder; import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory; import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; @@ -109,23 +107,19 @@ protected ValuesSourceAggregatorFactory innerBuild(QueryShardContext queryShardC @Override protected ValuesSourceConfig resolveConfig(QueryShardContext queryShardContext) { - ValuesSourceConfig config = new ValuesSourceConfig(CoreValuesSourceType.BYTES); - joinFieldResolveConfig(queryShardContext, config); - return config; - } - - private void joinFieldResolveConfig(QueryShardContext queryShardContext, ValuesSourceConfig config) { + ValuesSourceConfig config; ParentJoinFieldMapper parentJoinFieldMapper = ParentJoinFieldMapper.getMapper(queryShardContext.getMapperService()); ParentIdFieldMapper parentIdFieldMapper = parentJoinFieldMapper.getParentIdFieldMapper(childType, false); if (parentIdFieldMapper != null) { parentFilter = parentIdFieldMapper.getParentFilter(); childFilter = parentIdFieldMapper.getChildFilter(childType); MappedFieldType fieldType = parentIdFieldMapper.fieldType(); - final SortedSetDVOrdinalsIndexFieldData fieldData = queryShardContext.getForField(fieldType); - config.fieldContext(new FieldContext(fieldType.name(), fieldData, fieldType)); + config = ValuesSourceConfig.resolveFieldOnly(fieldType, queryShardContext); } else { - config.unmapped(true); + // unmapped case + config = ValuesSourceConfig.resolveUnmapped(defaultValueSourceType(), queryShardContext); } + return config; } @Override diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeValuesSourceBuilder.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeValuesSourceBuilder.java index 9ff057a35d232..7df525fb737d9 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeValuesSourceBuilder.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeValuesSourceBuilder.java @@ -26,6 +26,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.index.query.QueryShardContext; import org.elasticsearch.script.Script; +import org.elasticsearch.search.aggregations.support.CoreValuesSourceType; import org.elasticsearch.search.aggregations.support.ValueType; import org.elasticsearch.search.aggregations.support.ValuesSource; import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; @@ -277,7 +278,7 @@ protected abstract CompositeValuesSourceConfig innerBuild(QueryShardContext quer public final CompositeValuesSourceConfig build(QueryShardContext queryShardContext) throws IOException { ValuesSourceConfig config = ValuesSourceConfig.resolve(queryShardContext, - valueType, field, script, null, timeZone(), format, name()); + valueType, field, script, null, timeZone(), format, CoreValuesSourceType.BYTES, name()); return innerBuild(queryShardContext, config); } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/DateHistogramValuesSourceBuilder.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/DateHistogramValuesSourceBuilder.java index 33e5db10c4297..1caf22a23d36c 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/DateHistogramValuesSourceBuilder.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/DateHistogramValuesSourceBuilder.java @@ -252,7 +252,7 @@ public DateHistogramValuesSourceBuilder offset(long offset) { @Override protected CompositeValuesSourceConfig innerBuild(QueryShardContext queryShardContext, ValuesSourceConfig config) throws IOException { Rounding rounding = dateHistogramInterval.createRounding(timeZone(), offset); - ValuesSource orig = config.toValuesSource(queryShardContext); + ValuesSource orig = config.toValuesSource(); if (orig == null) { orig = ValuesSource.Numeric.EMPTY; } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/GeoTileGridValuesSourceBuilder.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/GeoTileGridValuesSourceBuilder.java index 4911cccabc05c..c74d62e623ebe 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/GeoTileGridValuesSourceBuilder.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/GeoTileGridValuesSourceBuilder.java @@ -129,7 +129,7 @@ public boolean equals(Object obj) { @Override protected CompositeValuesSourceConfig innerBuild(QueryShardContext queryShardContext, ValuesSourceConfig config) throws IOException { - ValuesSource orig = config.toValuesSource(queryShardContext); + ValuesSource orig = config.toValuesSource(); if (orig == null) { orig = ValuesSource.GeoPoint.EMPTY; } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/HistogramValuesSourceBuilder.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/HistogramValuesSourceBuilder.java index f88287daefe99..4ef15908ddd7a 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/HistogramValuesSourceBuilder.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/HistogramValuesSourceBuilder.java @@ -111,7 +111,7 @@ public HistogramValuesSourceBuilder interval(double interval) { @Override protected CompositeValuesSourceConfig innerBuild(QueryShardContext queryShardContext, ValuesSourceConfig config) throws IOException { - ValuesSource orig = config.toValuesSource(queryShardContext); + ValuesSource orig = config.toValuesSource(); if (orig == null) { orig = ValuesSource.Numeric.EMPTY; } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/TermsValuesSourceBuilder.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/TermsValuesSourceBuilder.java index 880fa360ea921..2954c155e0d7c 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/TermsValuesSourceBuilder.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/TermsValuesSourceBuilder.java @@ -71,7 +71,7 @@ public String type() { @Override protected CompositeValuesSourceConfig innerBuild(QueryShardContext queryShardContext, ValuesSourceConfig config) throws IOException { - ValuesSource vs = config.toValuesSource(queryShardContext); + ValuesSource vs = config.toValuesSource(); if (vs == null) { // The field is unmapped so we use a value source that can parse any type of values. // This is needed because the after values are parsed even when there are no values to process. diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/support/MultiValuesSource.java b/server/src/main/java/org/elasticsearch/search/aggregations/support/MultiValuesSource.java index 4efe04f18174a..fe1d5be993209 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/support/MultiValuesSource.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/support/MultiValuesSource.java @@ -39,7 +39,7 @@ public NumericMultiValuesSource(Map valuesSourceConf QueryShardContext context) { values = new HashMap<>(valuesSourceConfigs.size()); for (Map.Entry entry : valuesSourceConfigs.entrySet()) { - final ValuesSource valuesSource = entry.getValue().toValuesSource(context); + final ValuesSource valuesSource = entry.getValue().toValuesSource(); if (valuesSource instanceof ValuesSource.Numeric == false) { throw new AggregationExecutionException("ValuesSource type " + valuesSource.toString() + "is not supported for multi-valued aggregation"); diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceAggregatorFactory.java index 52954afdaac9c..d9cfc453d6e98 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceAggregatorFactory.java @@ -44,7 +44,7 @@ public ValuesSourceAggregatorFactory(String name, ValuesSourceConfig config, Que @Override public Aggregator createInternal(SearchContext searchContext, Aggregator parent, boolean collectsFromSingleBucket, List pipelineAggregators, Map metaData) throws IOException { - ValuesSource vs = config.toValuesSource(queryShardContext); + ValuesSource vs = config.toValuesSource(); if (vs == null) { return createUnmapped(searchContext, parent, pipelineAggregators, metaData); } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceConfig.java b/server/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceConfig.java index bf02d13c14f39..fa1cd558f8d09 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceConfig.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceConfig.java @@ -27,6 +27,7 @@ import org.elasticsearch.search.DocValueFormat; import java.time.ZoneId; +import java.util.function.LongSupplier; /** * A configuration that tells aggregations how to retrieve data from the index @@ -34,19 +35,6 @@ */ public class ValuesSourceConfig { - /** - * Resolve a {@link ValuesSourceConfig} given configuration parameters. - */ - public static ValuesSourceConfig resolve( - QueryShardContext context, - ValueType valueType, - String field, Script script, - Object missing, - ZoneId timeZone, - String format, String aggregationName) { - return resolve(context, valueType, field, script, missing, timeZone, format, CoreValuesSourceType.BYTES, aggregationName); - } - /** * Given the query context and other information, decide on the input {@link ValuesSource} for this aggretation run, and construct a new * {@link ValuesSourceConfig} based on that {@link ValuesSourceType} @@ -64,23 +52,26 @@ public static ValuesSourceConfig resolve( * {@link ValuesSourceRegistry} * @return - An initialized {@link ValuesSourceConfig} that will yield the appropriate {@link ValuesSourceType} */ - public static ValuesSourceConfig resolve( - QueryShardContext context, - ValueType userValueTypeHint, - String field, Script script, - Object missing, - ZoneId timeZone, - String format, - ValuesSourceType defaultValueSourceType, - String aggregationName) { + public static ValuesSourceConfig resolve(QueryShardContext context, + ValueType userValueTypeHint, + String field, + Script script, + Object missing, + ZoneId timeZone, + String format, + ValuesSourceType defaultValueSourceType, + String aggregationName) { ValuesSourceConfig config; MappedFieldType fieldType = null; ValuesSourceType valuesSourceType; + ValueType scriptValueType = null; + AggregationScript.LeafFactory aggregationScript = null; + boolean unmapped = false; if (field == null) { // Stand Alone Script Case if (script == null) { throw new IllegalStateException( - "value source config is invalid; must have either a field context or a script or marked as unwrapped"); + "value source config is invalid; must have either a field context or a script or marked as unmapped"); } /* * This is the Stand Alone Script path. We should have a script that will produce a value independent of the presence or @@ -92,9 +83,8 @@ public static ValuesSourceConfig resolve( } else { valuesSourceType = defaultValueSourceType; } - config = new ValuesSourceConfig(valuesSourceType); - config.script(createScript(script, context)); - config.scriptValueType(userValueTypeHint); + aggregationScript = createScript(script, context); + scriptValueType = userValueTypeHint; } else { // Field case fieldType = context.fieldMapper(field); @@ -104,30 +94,25 @@ public static ValuesSourceConfig resolve( * pattern. In this case, we're going to end up using the EMPTY variant of the ValuesSource, and possibly applying a user * specified missing value. */ - // TODO: This should be pluggable too; Effectively that will replace the missingAny() case from toValuesSource() if (userValueTypeHint != null) { valuesSourceType = userValueTypeHint.getValuesSourceType(); } else { valuesSourceType = defaultValueSourceType; } - config = new ValuesSourceConfig(valuesSourceType); - // TODO: PLAN - get rid of the unmapped flag field; it's only used by valid(), and we're intending to get rid of that. - // TODO: Once we no longer care about unmapped, we can merge this case with the mapped case. - config.unmapped(true); + unmapped = true; if (userValueTypeHint != null) { // todo do we really need this for unmapped? - config.scriptValueType(userValueTypeHint); + scriptValueType = userValueTypeHint; } } else { IndexFieldData indexFieldData = context.getForField(fieldType); valuesSourceType = context.getValuesSourceRegistry().getValuesSourceType(fieldType, aggregationName, indexFieldData, userValueTypeHint, script, defaultValueSourceType); - config = new ValuesSourceConfig(valuesSourceType); - config.fieldContext(new FieldContext(field, indexFieldData, fieldType)); - config.script(createScript(script, context)); + aggregationScript = createScript(script, context); } } + config = new ValuesSourceConfig(valuesSourceType, fieldType, unmapped, aggregationScript, scriptValueType , context); config.format(resolveFormat(format, valuesSourceType, timeZone, fieldType)); config.missing(missing); config.timezone(timeZone); @@ -152,21 +137,56 @@ private static DocValueFormat resolveFormat(@Nullable String format, @Nullable V return valuesSourceType.getFormatter(format, tz); } - private final ValuesSourceType valueSourceType; + /** + * Special case factory method, intended to be used by aggregations which have some specialized logic for figuring out what field they + * are operating on, for example Parent and Child join aggregations, which use the join relation to find the field they are reading from + * rather than a user specified field. + */ + public static ValuesSourceConfig resolveFieldOnly(MappedFieldType fieldType, + QueryShardContext queryShardContext) { + return new ValuesSourceConfig(fieldType.getValuesSourceType(), fieldType, false, null, null, queryShardContext); + } + + /** + * Convenience method for creating unmapped configs + */ + public static ValuesSourceConfig resolveUnmapped(ValuesSourceType valuesSourceType, QueryShardContext queryShardContext) { + return new ValuesSourceConfig(valuesSourceType, null, true, null, null, queryShardContext); + } + + private final ValuesSourceType valuesSourceType; private FieldContext fieldContext; private AggregationScript.LeafFactory script; private ValueType scriptValueType; - private boolean unmapped = false; + private boolean unmapped; private DocValueFormat format = DocValueFormat.RAW; private Object missing; private ZoneId timeZone; + private LongSupplier nowSupplier; + + + public ValuesSourceConfig(ValuesSourceType valuesSourceType, + MappedFieldType fieldType, + boolean unmapped, + AggregationScript.LeafFactory script, + ValueType scriptValueType, + QueryShardContext queryShardContext) { + if (unmapped && fieldType != 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.unmapped = unmapped; + this.script = script; + this.scriptValueType = scriptValueType; + this.nowSupplier = queryShardContext::nowInMillis; - public ValuesSourceConfig(ValuesSourceType valueSourceType) { - this.valueSourceType = valueSourceType; } public ValuesSourceType valueSourceType() { - return valueSourceType; + return valuesSourceType; } public FieldContext fieldContext() { @@ -185,36 +205,16 @@ public boolean valid() { return fieldContext != null || script != null || unmapped; } - public ValuesSourceConfig fieldContext(FieldContext fieldContext) { - this.fieldContext = fieldContext; - return this; - } - - public ValuesSourceConfig script(AggregationScript.LeafFactory script) { - this.script = script; - return this; - } - - private ValuesSourceConfig scriptValueType(ValueType scriptValueType) { - this.scriptValueType = scriptValueType; - return this; - } - public ValueType scriptValueType() { return this.scriptValueType; } - public ValuesSourceConfig unmapped(boolean unmapped) { - this.unmapped = unmapped; - return this; - } - - public ValuesSourceConfig format(final DocValueFormat format) { + private ValuesSourceConfig format(final DocValueFormat format) { this.format = format; return this; } - public ValuesSourceConfig missing(final Object missing) { + private ValuesSourceConfig missing(final Object missing) { this.missing = missing; return this; } @@ -223,7 +223,7 @@ public Object missing() { return this.missing; } - public ValuesSourceConfig timezone(final ZoneId timeZone) { + private ValuesSourceConfig timezone(final ZoneId timeZone) { this.timeZone = timeZone; return this; } @@ -238,12 +238,10 @@ public DocValueFormat format() { /** * Transform the {@link ValuesSourceType} we selected in resolve into the specific {@link ValuesSource} instance to use for this shard - * @param context - Literally just used to get the current time * @return - A {@link ValuesSource} ready to be read from by an aggregator */ @Nullable - // TODO: Replace QueryShardContext with a LongProvider - public ValuesSource toValuesSource(QueryShardContext context) { + public ValuesSource toValuesSource() { if (!valid()) { // TODO: resolve no longer generates invalid configs. Once VSConfig is immutable, we can drop this check throw new IllegalStateException( @@ -253,7 +251,9 @@ public ValuesSource toValuesSource(QueryShardContext context) { final ValuesSource vs; if (unmapped()) { if (missing() == null) { - // otherwise we will have values because of the missing value + /* Null values source signals to the AggregationBuilder to use the createUnmapped method, which aggregator factories can + * override to provide an aggregator optimized to return empty values + */ vs = null; } else { vs = valueSourceType().getEmpty(); @@ -271,6 +271,6 @@ public ValuesSource toValuesSource(QueryShardContext context) { if (missing() == null) { return vs; } - return valueSourceType().replaceMissing(vs, missing, format, context::nowInMillis); + return valueSourceType().replaceMissing(vs, missing, format, nowSupplier); } } diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/support/ValuesSourceConfigTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/support/ValuesSourceConfigTests.java index 43c5d76fe541a..25a71bd2ed39e 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/support/ValuesSourceConfigTests.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/support/ValuesSourceConfigTests.java @@ -46,8 +46,8 @@ public void testKeyword() throws Exception { QueryShardContext context = indexService.newQueryShardContext(0, searcher, () -> 42L, null); ValuesSourceConfig config = ValuesSourceConfig.resolve( - context, null, "bytes", null, null, null, null, null); - ValuesSource.Bytes valuesSource = (ValuesSource.Bytes) config.toValuesSource(context); + context, null, "bytes", null, null, null, null, CoreValuesSourceType.BYTES, null); + ValuesSource.Bytes valuesSource = (ValuesSource.Bytes) config.toValuesSource(); LeafReaderContext ctx = searcher.getIndexReader().leaves().get(0); SortedBinaryDocValues values = valuesSource.bytesValues(ctx); assertTrue(values.advanceExact(0)); @@ -68,15 +68,15 @@ public void testEmptyKeyword() throws Exception { QueryShardContext context = indexService.newQueryShardContext(0, searcher, () -> 42L, null); ValuesSourceConfig config = ValuesSourceConfig.resolve( - context, null, "bytes", null, null, null, null, null); - ValuesSource.Bytes valuesSource = (ValuesSource.Bytes) config.toValuesSource(context); + context, null, "bytes", null, null, null, null, CoreValuesSourceType.BYTES, null); + ValuesSource.Bytes valuesSource = (ValuesSource.Bytes) config.toValuesSource(); LeafReaderContext ctx = searcher.getIndexReader().leaves().get(0); SortedBinaryDocValues values = valuesSource.bytesValues(ctx); assertFalse(values.advanceExact(0)); config = ValuesSourceConfig.resolve( - context, null, "bytes", null, "abc", null, null, null); - valuesSource = (ValuesSource.Bytes) config.toValuesSource(context); + context, null, "bytes", null, "abc", null, null, CoreValuesSourceType.BYTES, null); + valuesSource = (ValuesSource.Bytes) config.toValuesSource(); values = valuesSource.bytesValues(ctx); assertTrue(values.advanceExact(0)); assertEquals(1, values.docValueCount()); @@ -94,13 +94,13 @@ public void testUnmappedKeyword() throws Exception { try (Engine.Searcher searcher = indexService.getShard(0).acquireSearcher("test")) { QueryShardContext context = indexService.newQueryShardContext(0, searcher, () -> 42L, null); ValuesSourceConfig config = ValuesSourceConfig.resolve( - context, ValueType.STRING, "bytes", null, null, null, null, null); - ValuesSource.Bytes valuesSource = (ValuesSource.Bytes) config.toValuesSource(context); + context, ValueType.STRING, "bytes", null, null, null, null, CoreValuesSourceType.BYTES, null); + ValuesSource.Bytes valuesSource = (ValuesSource.Bytes) config.toValuesSource(); assertNull(valuesSource); config = ValuesSourceConfig.resolve( - context, ValueType.STRING, "bytes", null, "abc", null, null, null); - valuesSource = (ValuesSource.Bytes) config.toValuesSource(context); + context, ValueType.STRING, "bytes", null, "abc", null, null, CoreValuesSourceType.BYTES, null); + valuesSource = (ValuesSource.Bytes) config.toValuesSource(); LeafReaderContext ctx = searcher.getIndexReader().leaves().get(0); SortedBinaryDocValues values = valuesSource.bytesValues(ctx); assertTrue(values.advanceExact(0)); @@ -121,8 +121,8 @@ public void testLong() throws Exception { QueryShardContext context = indexService.newQueryShardContext(0, searcher, () -> 42L, null); ValuesSourceConfig config = ValuesSourceConfig.resolve( - context, null, "long", null, null, null, null, null); - ValuesSource.Numeric valuesSource = (ValuesSource.Numeric) config.toValuesSource(context); + context, null, "long", null, null, null, null, CoreValuesSourceType.BYTES, null); + ValuesSource.Numeric valuesSource = (ValuesSource.Numeric) config.toValuesSource(); LeafReaderContext ctx = searcher.getIndexReader().leaves().get(0); SortedNumericDocValues values = valuesSource.longValues(ctx); assertTrue(values.advanceExact(0)); @@ -143,15 +143,15 @@ public void testEmptyLong() throws Exception { QueryShardContext context = indexService.newQueryShardContext(0, searcher, () -> 42L, null); ValuesSourceConfig config = ValuesSourceConfig.resolve( - context, null, "long", null, null, null, null, null); - ValuesSource.Numeric valuesSource = (ValuesSource.Numeric) config.toValuesSource(context); + context, null, "long", null, null, null, null, CoreValuesSourceType.BYTES, null); + ValuesSource.Numeric valuesSource = (ValuesSource.Numeric) config.toValuesSource(); LeafReaderContext ctx = searcher.getIndexReader().leaves().get(0); SortedNumericDocValues values = valuesSource.longValues(ctx); assertFalse(values.advanceExact(0)); config = ValuesSourceConfig.resolve( - context, null, "long", null, 42, null, null, null); - valuesSource = (ValuesSource.Numeric) config.toValuesSource(context); + context, null, "long", null, 42, null, null, CoreValuesSourceType.BYTES, null); + valuesSource = (ValuesSource.Numeric) config.toValuesSource(); values = valuesSource.longValues(ctx); assertTrue(values.advanceExact(0)); assertEquals(1, values.docValueCount()); @@ -170,13 +170,13 @@ public void testUnmappedLong() throws Exception { QueryShardContext context = indexService.newQueryShardContext(0, searcher, () -> 42L, null); ValuesSourceConfig config = ValuesSourceConfig.resolve( - context, ValueType.NUMBER, "long", null, null, null, null, null); - ValuesSource.Numeric valuesSource = (ValuesSource.Numeric) config.toValuesSource(context); + context, ValueType.NUMBER, "long", null, null, null, null, CoreValuesSourceType.BYTES, null); + ValuesSource.Numeric valuesSource = (ValuesSource.Numeric) config.toValuesSource(); assertNull(valuesSource); config = ValuesSourceConfig.resolve( - context, ValueType.NUMBER, "long", null, 42, null, null, null); - valuesSource = (ValuesSource.Numeric) config.toValuesSource(context); + context, ValueType.NUMBER, "long", null, 42, null, null, CoreValuesSourceType.BYTES, null); + valuesSource = (ValuesSource.Numeric) config.toValuesSource(); LeafReaderContext ctx = searcher.getIndexReader().leaves().get(0); SortedNumericDocValues values = valuesSource.longValues(ctx); assertTrue(values.advanceExact(0)); @@ -197,8 +197,8 @@ public void testBoolean() throws Exception { QueryShardContext context = indexService.newQueryShardContext(0, searcher, () -> 42L, null); ValuesSourceConfig config = ValuesSourceConfig.resolve( - context, null, "bool", null, null, null, null, null); - ValuesSource.Numeric valuesSource = (ValuesSource.Numeric) config.toValuesSource(context); + context, null, "bool", null, null, null, null, CoreValuesSourceType.BYTES, null); + ValuesSource.Numeric valuesSource = (ValuesSource.Numeric) config.toValuesSource(); LeafReaderContext ctx = searcher.getIndexReader().leaves().get(0); SortedNumericDocValues values = valuesSource.longValues(ctx); assertTrue(values.advanceExact(0)); @@ -219,15 +219,15 @@ public void testEmptyBoolean() throws Exception { QueryShardContext context = indexService.newQueryShardContext(0, searcher, () -> 42L, null); ValuesSourceConfig config = ValuesSourceConfig.resolve( - context, null, "bool", null, null, null, null, null); - ValuesSource.Numeric valuesSource = (ValuesSource.Numeric) config.toValuesSource(context); + context, null, "bool", null, null, null, null, CoreValuesSourceType.BYTES, null); + ValuesSource.Numeric valuesSource = (ValuesSource.Numeric) config.toValuesSource(); LeafReaderContext ctx = searcher.getIndexReader().leaves().get(0); SortedNumericDocValues values = valuesSource.longValues(ctx); assertFalse(values.advanceExact(0)); config = ValuesSourceConfig.resolve( - context, null, "bool", null, true, null, null, null); - valuesSource = (ValuesSource.Numeric) config.toValuesSource(context); + context, null, "bool", null, true, null, null, CoreValuesSourceType.BYTES, null); + valuesSource = (ValuesSource.Numeric) config.toValuesSource(); values = valuesSource.longValues(ctx); assertTrue(values.advanceExact(0)); assertEquals(1, values.docValueCount()); @@ -246,13 +246,13 @@ public void testUnmappedBoolean() throws Exception { QueryShardContext context = indexService.newQueryShardContext(0, searcher, () -> 42L, null); ValuesSourceConfig config = ValuesSourceConfig.resolve( - context, ValueType.BOOLEAN, "bool", null, null, null, null, null); - ValuesSource.Numeric valuesSource = (ValuesSource.Numeric) config.toValuesSource(context); + context, ValueType.BOOLEAN, "bool", null, null, null, null, CoreValuesSourceType.BYTES, null); + ValuesSource.Numeric valuesSource = (ValuesSource.Numeric) config.toValuesSource(); assertNull(valuesSource); config = ValuesSourceConfig.resolve( - context, ValueType.BOOLEAN, "bool", null, true, null, null, null); - valuesSource = (ValuesSource.Numeric) config.toValuesSource(context); + context, ValueType.BOOLEAN, "bool", null, true, null, null, CoreValuesSourceType.BYTES, null); + valuesSource = (ValuesSource.Numeric) config.toValuesSource(); LeafReaderContext ctx = searcher.getIndexReader().leaves().get(0); SortedNumericDocValues values = valuesSource.longValues(ctx); assertTrue(values.advanceExact(0)); @@ -267,7 +267,7 @@ public void testTypeFieldDeprecation() { QueryShardContext context = indexService.newQueryShardContext(0, searcher, () -> 42L, null); ValuesSourceConfig config = ValuesSourceConfig.resolve( - context, null, TypeFieldMapper.NAME, null, null, null, null, null); + context, null, TypeFieldMapper.NAME, null, null, null, null, CoreValuesSourceType.BYTES, null); assertWarnings(QueryShardContext.TYPES_DEPRECATION_MESSAGE); } } @@ -283,8 +283,8 @@ public void testFieldAlias() throws Exception { try (Engine.Searcher searcher = indexService.getShard(0).acquireSearcher("test")) { QueryShardContext context = indexService.newQueryShardContext(0, searcher, () -> 42L, null); ValuesSourceConfig config = ValuesSourceConfig.resolve( - context, ValueType.STRING, "alias", null, null, null, null, null); - ValuesSource.Bytes valuesSource = (ValuesSource.Bytes) config.toValuesSource(context); + context, ValueType.STRING, "alias", null, null, null, null, CoreValuesSourceType.BYTES, null); + ValuesSource.Bytes valuesSource = (ValuesSource.Bytes) config.toValuesSource(); LeafReaderContext ctx = searcher.getIndexReader().leaves().get(0); SortedBinaryDocValues values = valuesSource.bytesValues(ctx); diff --git a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/topmetrics/TopMetricsAggregatorFactory.java b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/topmetrics/TopMetricsAggregatorFactory.java index e257ef1357eff..aa796bb4075f4 100644 --- a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/topmetrics/TopMetricsAggregatorFactory.java +++ b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/topmetrics/TopMetricsAggregatorFactory.java @@ -42,7 +42,7 @@ protected TopMetricsAggregator createInternal(SearchContext searchContext, Aggre ValuesSourceConfig metricFieldSource = ValuesSourceConfig.resolve(queryShardContext, ValueType.NUMERIC, metricField.getFieldName(), metricField.getScript(), metricField.getMissing(), metricField.getTimeZone(), null, CoreValuesSourceType.NUMERIC, TopMetricsAggregationBuilder.NAME); - ValuesSource.Numeric metricValueSource = (ValuesSource.Numeric) metricFieldSource.toValuesSource(queryShardContext); + ValuesSource.Numeric metricValueSource = (ValuesSource.Numeric) metricFieldSource.toValuesSource(); if (metricValueSource == null) { return createUnmapped(searchContext, parent, pipelineAggregators, metaData); } diff --git a/x-pack/plugin/analytics/src/test/java/org/elasticsearch/xpack/analytics/cumulativecardinality/CumulativeCardinalityAggregatorTests.java b/x-pack/plugin/analytics/src/test/java/org/elasticsearch/xpack/analytics/cumulativecardinality/CumulativeCardinalityAggregatorTests.java index ada59511a2b29..c939e105ea0e8 100644 --- a/x-pack/plugin/analytics/src/test/java/org/elasticsearch/xpack/analytics/cumulativecardinality/CumulativeCardinalityAggregatorTests.java +++ b/x-pack/plugin/analytics/src/test/java/org/elasticsearch/xpack/analytics/cumulativecardinality/CumulativeCardinalityAggregatorTests.java @@ -117,7 +117,7 @@ public void testAllNull() throws IOException { } public void testParentValidations() throws IOException { - ValuesSourceConfig valuesSource = new ValuesSourceConfig(CoreValuesSourceType.NUMERIC); + ValuesSourceConfig valuesSource = ValuesSourceConfig.resolveUnmapped(CoreValuesSourceType.NUMERIC, mock(QueryShardContext.class)); // Histogram Set aggBuilders = new HashSet<>(); @@ -140,7 +140,7 @@ public void testParentValidations() throws IOException { builder.validate(parent, Collections.emptySet(), aggBuilders); // Auto Date Histogram - ValuesSourceConfig numericVS = new ValuesSourceConfig(CoreValuesSourceType.NUMERIC); + ValuesSourceConfig numericVS = ValuesSourceConfig.resolveUnmapped(CoreValuesSourceType.NUMERIC, mock(QueryShardContext.class)); aggBuilders.clear(); aggBuilders.add(new CumulativeCardinalityPipelineAggregationBuilder("cumulative_card", "sum")); AutoDateHistogramAggregationBuilder.RoundingInfo[] roundings = new AutoDateHistogramAggregationBuilder.RoundingInfo[1];