Class ValuesSourceConfig
java.lang.Object
org.elasticsearch.search.aggregations.support.ValuesSourceConfig
public class ValuesSourceConfig
extends java.lang.Object
A configuration that tells aggregations how to retrieve data from the index
in order to run a specific aggregation.
-
Constructor Summary
Constructors Constructor Description ValuesSourceConfig(ValuesSourceType valuesSourceType, FieldContext fieldContext, boolean unmapped, AggregationScript.LeafFactory script, ValueType scriptValueType, java.lang.Object missing, java.time.ZoneId timeZone, DocValueFormat format, java.util.function.LongSupplier nowSupplier) -
Method Summary
Modifier and Type Method Description FieldContextfieldContext()MappedFieldTypefieldType()Convenience method for looking up the mapped field type backing this values source, if it exists.DocValueFormatformat()java.lang.StringgetDescription()Returns a human readable description of this values source, for use in error messages and similar.java.util.function.Function<byte[],java.lang.Number>getPointReaderOrNull()This method is used when an aggregation can optimize by using the indexed data instead of the doc values.ValuesSourcegetValuesSource()booleanhasGlobalOrdinals()booleanhasValues()Returns true if the values source configured by this object can yield values.java.lang.Objectmissing()static ValuesSourceConfigresolve(QueryShardContext context, ValueType userValueTypeHint, java.lang.String field, Script script, java.lang.Object missing, java.time.ZoneId timeZone, java.lang.String format, ValuesSourceType defaultValueSourceType)Given the query context and other information, decide on the inputValuesSourcefor this aggretation run, and construct a newValuesSourceConfigbased on thatValuesSourceTypestatic ValuesSourceConfigresolveFieldOnly(MappedFieldType fieldType, QueryShardContext queryShardContext)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.static ValuesSourceConfigresolveUnmapped(ValuesSourceType valuesSourceType, QueryShardContext queryShardContext)Convenience method for creating unmapped configsstatic ValuesSourceConfigresolveUnregistered(QueryShardContext context, ValueType userValueTypeHint, java.lang.String field, Script script, java.lang.Object missing, java.time.ZoneId timeZone, java.lang.String format, ValuesSourceType defaultValueSourceType)AKA legacy resolve.AggregationScript.LeafFactoryscript()ValueTypescriptValueType()java.time.ZoneIdtimezone()booleanvalid()ValuesSourceTypevalueSourceType()
-
Constructor Details
-
ValuesSourceConfig
public ValuesSourceConfig(ValuesSourceType valuesSourceType, FieldContext fieldContext, boolean unmapped, AggregationScript.LeafFactory script, ValueType scriptValueType, java.lang.Object missing, java.time.ZoneId timeZone, DocValueFormat format, java.util.function.LongSupplier nowSupplier)
-
-
Method Details
-
resolve
public static ValuesSourceConfig resolve(QueryShardContext context, ValueType userValueTypeHint, java.lang.String field, Script script, java.lang.Object missing, java.time.ZoneId timeZone, java.lang.String format, ValuesSourceType defaultValueSourceType)Given the query context and other information, decide on the inputValuesSourcefor this aggretation run, and construct a newValuesSourceConfigbased on thatValuesSourceType- Parameters:
context- - the query contextuserValueTypeHint- - User specified value type; used for missing values and scriptsfield- - The field being aggregated over. At least one of field and script must not be nullscript- - The script the user specified. At least one of field and script must not be nullmissing- - A user specified value to apply when the field is missing. Should be of type userValueTypeHinttimeZone- - Used to generate a format for datesformat- - 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/47469defaultValueSourceType- - per-aggregationValuesSourceof last resort.- Returns:
- - An initialized
ValuesSourceConfigthat will yield the appropriateValuesSourceType
-
resolveUnregistered
public static ValuesSourceConfig resolveUnregistered(QueryShardContext context, ValueType userValueTypeHint, java.lang.String field, Script script, java.lang.Object missing, java.time.ZoneId timeZone, java.lang.String format, ValuesSourceType defaultValueSourceType)AKA legacy resolve. This method should be called by aggregations not supported by theValuesSourceRegistry, to use the pre-registry logic to decide on theValuesSourceType. New aggregations which extend fromValuesSourceAggregationBuildershould not use this method, preferringresolve(org.elasticsearch.index.query.QueryShardContext, org.elasticsearch.search.aggregations.support.ValueType, java.lang.String, org.elasticsearch.script.Script, java.lang.Object, java.time.ZoneId, java.lang.String, org.elasticsearch.search.aggregations.support.ValuesSourceType)instead.- Parameters:
context- - the query contextuserValueTypeHint- - User specified value type; used for missing values and scriptsfield- - The field being aggregated over. At least one of field and script must not be nullscript- - The script the user specified. At least one of field and script must not be nullmissing- - A user specified value to apply when the field is missing. Should be of type userValueTypeHinttimeZone- - Used to generate a format for datesformat- - 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/47469defaultValueSourceType- - per-aggregationValuesSourceof last resort.- Returns:
- - An initialized
ValuesSourceConfigthat will yield the appropriateValuesSourceType
-
resolveFieldOnly
public static ValuesSourceConfig resolveFieldOnly(MappedFieldType fieldType, QueryShardContext queryShardContext)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. -
resolveUnmapped
public static ValuesSourceConfig resolveUnmapped(ValuesSourceType valuesSourceType, QueryShardContext queryShardContext)Convenience method for creating unmapped configs -
valueSourceType
-
fieldContext
-
fieldType
Convenience method for looking up the mapped field type backing this values source, if it exists. -
script
-
hasValues
public boolean hasValues()Returns true if the values source configured by this object can yield values. We might not be able to yield values if, for example, the specified field does not exist on this index. -
valid
public boolean valid() -
scriptValueType
-
missing
public java.lang.Object missing() -
timezone
public java.time.ZoneId timezone() -
format
-
getValuesSource
-
hasGlobalOrdinals
public boolean hasGlobalOrdinals() -
getPointReaderOrNull
@Nullable public java.util.function.Function<byte[],java.lang.Number> getPointReaderOrNull()This method is used when an aggregation can optimize by using the indexed data instead of the doc values. We check to see if the indexed data will match the values source output (meaning there isn't a script or a missing value, since both could modify the value at read time). If the settings allow for it, we then ask theValuesSourceTypeto build the actual point reader based on the field type. This allows for a point of extensibility in plugins.- Returns:
- null if we cannot apply the optimization, otherwise the point reader function.
-
getDescription
public java.lang.String getDescription()Returns a human readable description of this values source, for use in error messages and similar.
-