parent
61142a3005
commit
52806a8f89
|
@ -260,7 +260,7 @@ public class DateHistogramValuesSourceBuilder
|
|||
RoundingValuesSource vs = new RoundingValuesSource(numeric, preparedRounding);
|
||||
// is specified in the builder.
|
||||
final DocValueFormat docValueFormat = format() == null ? DocValueFormat.RAW : config.format();
|
||||
final MappedFieldType fieldType = config.fieldContext() != null ? config.fieldContext().fieldType() : null;
|
||||
final MappedFieldType fieldType = config.fieldType();
|
||||
return new CompositeValuesSourceConfig(name, fieldType, vs, docValueFormat, order(),
|
||||
missingBucket(), config.script() != null);
|
||||
} else {
|
||||
|
|
|
@ -136,7 +136,7 @@ public class GeoTileGridValuesSourceBuilder extends CompositeValuesSourceBuilder
|
|||
if (orig instanceof ValuesSource.GeoPoint) {
|
||||
ValuesSource.GeoPoint geoPoint = (ValuesSource.GeoPoint) orig;
|
||||
// is specified in the builder.
|
||||
final MappedFieldType fieldType = config.fieldContext() != null ? config.fieldContext().fieldType() : null;
|
||||
final MappedFieldType fieldType = config.fieldType();
|
||||
CellIdSource cellIdSource = new CellIdSource(geoPoint, precision, geoBoundingBox, GeoTileUtils::longEncode);
|
||||
return new CompositeValuesSourceConfig(name, fieldType, cellIdSource, DocValueFormat.GEOTILE, order(),
|
||||
missingBucket(), script() != null);
|
||||
|
|
|
@ -118,7 +118,7 @@ public class HistogramValuesSourceBuilder extends CompositeValuesSourceBuilder<H
|
|||
if (orig instanceof ValuesSource.Numeric) {
|
||||
ValuesSource.Numeric numeric = (ValuesSource.Numeric) orig;
|
||||
final HistogramValuesSource vs = new HistogramValuesSource(numeric, interval);
|
||||
final MappedFieldType fieldType = config.fieldContext() != null ? config.fieldContext().fieldType() : null;
|
||||
final MappedFieldType fieldType = config.fieldType();
|
||||
return new CompositeValuesSourceConfig(name, fieldType, vs, config.format(), order(),
|
||||
missingBucket(), script() != null);
|
||||
} else {
|
||||
|
|
|
@ -77,7 +77,7 @@ public class TermsValuesSourceBuilder extends CompositeValuesSourceBuilder<Terms
|
|||
// This is needed because the after values are parsed even when there are no values to process.
|
||||
vs = ValuesSource.Bytes.WithOrdinals.EMPTY;
|
||||
}
|
||||
final MappedFieldType fieldType = config.fieldContext() != null ? config.fieldContext().fieldType() : null;
|
||||
final MappedFieldType fieldType = config.fieldType();
|
||||
final DocValueFormat format;
|
||||
if (format() == null && fieldType instanceof DateFieldMapper.DateFieldType) {
|
||||
// defaults to the raw format on date fields (preserve timestamp as longs).
|
||||
|
|
|
@ -365,7 +365,7 @@ public abstract class ValuesSourceAggregationBuilder<AB extends ValuesSourceAggr
|
|||
|
||||
protected ValuesSourceConfig resolveConfig(QueryShardContext queryShardContext) {
|
||||
return ValuesSourceConfig.resolve(queryShardContext,
|
||||
this.userValueTypeHint, field, script, missing, timeZone, format, this.defaultValueSourceType(), this.getType());
|
||||
this.userValueTypeHint, field, script, missing, timeZone, format, this.defaultValueSourceType());
|
||||
}
|
||||
|
||||
protected abstract ValuesSourceAggregatorFactory innerBuild(QueryShardContext queryShardContext,
|
||||
|
|
|
@ -51,8 +51,6 @@ public class ValuesSourceConfig {
|
|||
* @param format - The format string to apply to this field. Confusingly, this is used for input parsing as well as output formatting
|
||||
* See https://github.com/elastic/elasticsearch/issues/47469
|
||||
* @param defaultValueSourceType - per-aggregation {@link ValuesSource} of last resort.
|
||||
* @param aggregationName - Name of the aggregation, generally from the aggregation builder. This is used as a lookup key in the
|
||||
* {@link ValuesSourceRegistry}
|
||||
* @return - An initialized {@link ValuesSourceConfig} that will yield the appropriate {@link ValuesSourceType}
|
||||
*/
|
||||
public static ValuesSourceConfig resolve(QueryShardContext context,
|
||||
|
@ -62,8 +60,7 @@ public class ValuesSourceConfig {
|
|||
Object missing,
|
||||
ZoneId timeZone,
|
||||
String format,
|
||||
ValuesSourceType defaultValueSourceType,
|
||||
String aggregationName) {
|
||||
ValuesSourceType defaultValueSourceType) {
|
||||
|
||||
return internalResolve(context, userValueTypeHint, field, script, missing, timeZone, format, defaultValueSourceType,
|
||||
ValuesSourceConfig::getMappingFromRegistry
|
||||
|
@ -261,7 +258,6 @@ public class ValuesSourceConfig {
|
|||
private final DocValueFormat format;
|
||||
private final Object missing;
|
||||
private final ZoneId timeZone;
|
||||
private final LongSupplier nowSupplier;
|
||||
private final ValuesSource valuesSource;
|
||||
|
||||
private ValuesSourceConfig() {
|
||||
|
@ -290,7 +286,6 @@ public class ValuesSourceConfig {
|
|||
this.missing = missing;
|
||||
this.timeZone = timeZone;
|
||||
this.format = format == null ? DocValueFormat.RAW : format;
|
||||
this.nowSupplier = nowSupplier;
|
||||
|
||||
if (!valid()) {
|
||||
// TODO: resolve no longer generates invalid configs. Once VSConfig is immutable, we can drop this check
|
||||
|
@ -329,6 +324,14 @@ public class ValuesSourceConfig {
|
|||
return fieldContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method for looking up the mapped field type backing this values source, if it exists.
|
||||
*/
|
||||
@Nullable
|
||||
public MappedFieldType fieldType() {
|
||||
return fieldContext == null ? null : fieldContext.fieldType();
|
||||
}
|
||||
|
||||
public AggregationScript.LeafFactory script() {
|
||||
return script;
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ public class ValuesSourceConfigTests extends ESSingleNodeTestCase {
|
|||
QueryShardContext context = indexService.newQueryShardContext(0, searcher, () -> 42L, null);
|
||||
|
||||
ValuesSourceConfig config = ValuesSourceConfig.resolve(
|
||||
context, null, "bytes", null, null, null, null, CoreValuesSourceType.BYTES, null);
|
||||
context, null, "bytes", null, null, null, null, CoreValuesSourceType.BYTES);
|
||||
ValuesSource.Bytes valuesSource = (ValuesSource.Bytes) config.getValuesSource();
|
||||
LeafReaderContext ctx = searcher.getIndexReader().leaves().get(0);
|
||||
SortedBinaryDocValues values = valuesSource.bytesValues(ctx);
|
||||
|
@ -68,14 +68,14 @@ public class ValuesSourceConfigTests extends ESSingleNodeTestCase {
|
|||
QueryShardContext context = indexService.newQueryShardContext(0, searcher, () -> 42L, null);
|
||||
|
||||
ValuesSourceConfig config = ValuesSourceConfig.resolve(
|
||||
context, null, "bytes", null, null, null, null, CoreValuesSourceType.BYTES, null);
|
||||
context, null, "bytes", null, null, null, null, CoreValuesSourceType.BYTES);
|
||||
ValuesSource.Bytes valuesSource = (ValuesSource.Bytes) config.getValuesSource();
|
||||
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, CoreValuesSourceType.BYTES, null);
|
||||
context, null, "bytes", null, "abc", null, null, CoreValuesSourceType.BYTES);
|
||||
valuesSource = (ValuesSource.Bytes) config.getValuesSource();
|
||||
values = valuesSource.bytesValues(ctx);
|
||||
assertTrue(values.advanceExact(0));
|
||||
|
@ -94,13 +94,13 @@ public class ValuesSourceConfigTests extends ESSingleNodeTestCase {
|
|||
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, CoreValuesSourceType.BYTES, null);
|
||||
context, ValueType.STRING, "bytes", null, null, null, null, CoreValuesSourceType.BYTES);
|
||||
ValuesSource.Bytes valuesSource = (ValuesSource.Bytes) config.getValuesSource();
|
||||
assertNotNull(valuesSource);
|
||||
assertFalse(config.hasValues());
|
||||
|
||||
config = ValuesSourceConfig.resolve(
|
||||
context, ValueType.STRING, "bytes", null, "abc", null, null, CoreValuesSourceType.BYTES, null);
|
||||
context, ValueType.STRING, "bytes", null, "abc", null, null, CoreValuesSourceType.BYTES);
|
||||
valuesSource = (ValuesSource.Bytes) config.getValuesSource();
|
||||
LeafReaderContext ctx = searcher.getIndexReader().leaves().get(0);
|
||||
SortedBinaryDocValues values = valuesSource.bytesValues(ctx);
|
||||
|
@ -122,7 +122,7 @@ public class ValuesSourceConfigTests extends ESSingleNodeTestCase {
|
|||
QueryShardContext context = indexService.newQueryShardContext(0, searcher, () -> 42L, null);
|
||||
|
||||
ValuesSourceConfig config = ValuesSourceConfig.resolve(
|
||||
context, null, "long", null, null, null, null, CoreValuesSourceType.BYTES, null);
|
||||
context, null, "long", null, null, null, null, CoreValuesSourceType.BYTES);
|
||||
ValuesSource.Numeric valuesSource = (ValuesSource.Numeric) config.getValuesSource();
|
||||
LeafReaderContext ctx = searcher.getIndexReader().leaves().get(0);
|
||||
SortedNumericDocValues values = valuesSource.longValues(ctx);
|
||||
|
@ -144,14 +144,14 @@ public class ValuesSourceConfigTests extends ESSingleNodeTestCase {
|
|||
QueryShardContext context = indexService.newQueryShardContext(0, searcher, () -> 42L, null);
|
||||
|
||||
ValuesSourceConfig config = ValuesSourceConfig.resolve(
|
||||
context, null, "long", null, null, null, null, CoreValuesSourceType.BYTES, null);
|
||||
context, null, "long", null, null, null, null, CoreValuesSourceType.BYTES);
|
||||
ValuesSource.Numeric valuesSource = (ValuesSource.Numeric) config.getValuesSource();
|
||||
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, CoreValuesSourceType.BYTES, null);
|
||||
context, null, "long", null, 42, null, null, CoreValuesSourceType.BYTES);
|
||||
valuesSource = (ValuesSource.Numeric) config.getValuesSource();
|
||||
values = valuesSource.longValues(ctx);
|
||||
assertTrue(values.advanceExact(0));
|
||||
|
@ -171,13 +171,13 @@ public class ValuesSourceConfigTests extends ESSingleNodeTestCase {
|
|||
QueryShardContext context = indexService.newQueryShardContext(0, searcher, () -> 42L, null);
|
||||
|
||||
ValuesSourceConfig config = ValuesSourceConfig.resolve(
|
||||
context, ValueType.NUMBER, "long", null, null, null, null, CoreValuesSourceType.BYTES, null);
|
||||
context, ValueType.NUMBER, "long", null, null, null, null, CoreValuesSourceType.BYTES);
|
||||
ValuesSource.Numeric valuesSource = (ValuesSource.Numeric) config.getValuesSource();
|
||||
assertNotNull(valuesSource);
|
||||
assertFalse(config.hasValues());
|
||||
|
||||
config = ValuesSourceConfig.resolve(
|
||||
context, ValueType.NUMBER, "long", null, 42, null, null, CoreValuesSourceType.BYTES, null);
|
||||
context, ValueType.NUMBER, "long", null, 42, null, null, CoreValuesSourceType.BYTES);
|
||||
valuesSource = (ValuesSource.Numeric) config.getValuesSource();
|
||||
LeafReaderContext ctx = searcher.getIndexReader().leaves().get(0);
|
||||
SortedNumericDocValues values = valuesSource.longValues(ctx);
|
||||
|
@ -199,7 +199,7 @@ public class ValuesSourceConfigTests extends ESSingleNodeTestCase {
|
|||
QueryShardContext context = indexService.newQueryShardContext(0, searcher, () -> 42L, null);
|
||||
|
||||
ValuesSourceConfig config = ValuesSourceConfig.resolve(
|
||||
context, null, "bool", null, null, null, null, CoreValuesSourceType.BYTES, null);
|
||||
context, null, "bool", null, null, null, null, CoreValuesSourceType.BYTES);
|
||||
ValuesSource.Numeric valuesSource = (ValuesSource.Numeric) config.getValuesSource();
|
||||
LeafReaderContext ctx = searcher.getIndexReader().leaves().get(0);
|
||||
SortedNumericDocValues values = valuesSource.longValues(ctx);
|
||||
|
@ -221,14 +221,14 @@ public class ValuesSourceConfigTests extends ESSingleNodeTestCase {
|
|||
QueryShardContext context = indexService.newQueryShardContext(0, searcher, () -> 42L, null);
|
||||
|
||||
ValuesSourceConfig config = ValuesSourceConfig.resolve(
|
||||
context, null, "bool", null, null, null, null, CoreValuesSourceType.BYTES, null);
|
||||
context, null, "bool", null, null, null, null, CoreValuesSourceType.BYTES);
|
||||
ValuesSource.Numeric valuesSource = (ValuesSource.Numeric) config.getValuesSource();
|
||||
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, CoreValuesSourceType.BYTES, null);
|
||||
context, null, "bool", null, true, null, null, CoreValuesSourceType.BYTES);
|
||||
valuesSource = (ValuesSource.Numeric) config.getValuesSource();
|
||||
values = valuesSource.longValues(ctx);
|
||||
assertTrue(values.advanceExact(0));
|
||||
|
@ -248,13 +248,13 @@ public class ValuesSourceConfigTests extends ESSingleNodeTestCase {
|
|||
QueryShardContext context = indexService.newQueryShardContext(0, searcher, () -> 42L, null);
|
||||
|
||||
ValuesSourceConfig config = ValuesSourceConfig.resolve(
|
||||
context, ValueType.BOOLEAN, "bool", null, null, null, null, CoreValuesSourceType.BYTES, null);
|
||||
context, ValueType.BOOLEAN, "bool", null, null, null, null, CoreValuesSourceType.BYTES);
|
||||
ValuesSource.Numeric valuesSource = (ValuesSource.Numeric) config.getValuesSource();
|
||||
assertNotNull(valuesSource);
|
||||
assertFalse(config.hasValues());
|
||||
|
||||
config = ValuesSourceConfig.resolve(
|
||||
context, ValueType.BOOLEAN, "bool", null, true, null, null, CoreValuesSourceType.BYTES, null);
|
||||
context, ValueType.BOOLEAN, "bool", null, true, null, null, CoreValuesSourceType.BYTES);
|
||||
valuesSource = (ValuesSource.Numeric) config.getValuesSource();
|
||||
LeafReaderContext ctx = searcher.getIndexReader().leaves().get(0);
|
||||
SortedNumericDocValues values = valuesSource.longValues(ctx);
|
||||
|
@ -270,7 +270,7 @@ public class ValuesSourceConfigTests extends ESSingleNodeTestCase {
|
|||
QueryShardContext context = indexService.newQueryShardContext(0, searcher, () -> 42L, null);
|
||||
|
||||
ValuesSourceConfig config = ValuesSourceConfig.resolve(
|
||||
context, null, TypeFieldMapper.NAME, null, null, null, null, CoreValuesSourceType.BYTES, null);
|
||||
context, null, TypeFieldMapper.NAME, null, null, null, null, CoreValuesSourceType.BYTES);
|
||||
assertWarnings(QueryShardContext.TYPES_DEPRECATION_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
@ -286,7 +286,7 @@ public class ValuesSourceConfigTests extends ESSingleNodeTestCase {
|
|||
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, CoreValuesSourceType.BYTES, null);
|
||||
context, ValueType.STRING, "alias", null, null, null, null, CoreValuesSourceType.BYTES);
|
||||
ValuesSource.Bytes valuesSource = (ValuesSource.Bytes) config.getValuesSource();
|
||||
|
||||
LeafReaderContext ctx = searcher.getIndexReader().leaves().get(0);
|
||||
|
|
|
@ -61,7 +61,7 @@ public class TopMetricsAggregatorFactory extends AggregatorFactory {
|
|||
ValuesSourceConfig resolved = ValuesSourceConfig.resolve(
|
||||
searchContext.getQueryShardContext(), ValueType.NUMERIC,
|
||||
config.getFieldName(), config.getScript(), config.getMissing(), config.getTimeZone(), null,
|
||||
CoreValuesSourceType.NUMERIC, TopMetricsAggregationBuilder.NAME);
|
||||
CoreValuesSourceType.NUMERIC);
|
||||
return new TopMetricsAggregator.MetricSource(config.getFieldName(), resolved.format(),
|
||||
(ValuesSource.Numeric) resolved.getValuesSource());
|
||||
}).collect(toList());
|
||||
|
|
Loading…
Reference in New Issue