Class ValuesSourceConfig

java.lang.Object
org.elasticsearch.search.aggregations.support.ValuesSourceConfig

public class ValuesSourceConfig extends Object
A configuration that tells aggregations how to retrieve data from the index in order to run a specific aggregation.
  • Constructor Details

  • Method Details

    • resolve

      public static ValuesSourceConfig resolve(AggregationContext context, ValueType userValueTypeHint, String field, Script script, Object missing, ZoneId timeZone, String format, ValuesSourceType defaultValueSourceType)
      Given the query context and other information, decide on the input ValuesSource for this aggretation run, and construct a new ValuesSourceConfig based on that ValuesSourceType
      Parameters:
      context - - the query context
      userValueTypeHint - - User specified value type; used for missing values and scripts
      field - - The field being aggregated over. At least one of field and script must not be null
      script - - The script the user specified. At least one of field and script must not be null
      missing - - A user specified value to apply when the field is missing. Should be of type userValueTypeHint
      timeZone - - Used to generate a format for dates
      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
      defaultValueSourceType - - per-aggregation ValuesSource of last resort.
      Returns:
      - An initialized ValuesSourceConfig that will yield the appropriate ValuesSourceType
    • resolveUnregistered

      public static ValuesSourceConfig resolveUnregistered(AggregationContext context, ValueType userValueTypeHint, String field, Script script, Object missing, ZoneId timeZone, String format, ValuesSourceType defaultValueSourceType)
      Parameters:
      context - - the query context
      userValueTypeHint - - User specified value type; used for missing values and scripts
      field - - The field being aggregated over. At least one of field and script must not be null
      script - - The script the user specified. At least one of field and script must not be null
      missing - - A user specified value to apply when the field is missing. Should be of type userValueTypeHint
      timeZone - - Used to generate a format for dates
      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
      defaultValueSourceType - - per-aggregation ValuesSource of last resort.
      Returns:
      - An initialized ValuesSourceConfig that will yield the appropriate ValuesSourceType
    • resolveFieldOnly

      public static ValuesSourceConfig resolveFieldOnly(MappedFieldType fieldType, AggregationContext context)
      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, AggregationContext context)
      Convenience method for creating unmapped configs
    • valueSourceType

      public ValuesSourceType valueSourceType()
    • fieldContext

      public FieldContext fieldContext()
    • fieldType

      @Nullable public MappedFieldType 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

      public ValueType scriptValueType()
    • missing

      public Object missing()
    • timezone

      public ZoneId timezone()
    • format

      public DocValueFormat format()
    • getValuesSource

      public ValuesSource getValuesSource()
    • roundingPreparer

      public Function<Rounding,Rounding.Prepared> roundingPreparer() throws IOException
      Build a function prepares rounding values to be called many times.

      This returns a Function because auto date histogram will need to call it many times over the course of running the aggregation.

      Throws:
      IOException
    • hasOrdinals

      public boolean hasOrdinals()
      Check if this values source supports using global and segment ordinals.
    • getPointReaderOrNull

      @Nullable public Function<byte[],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 the ValuesSourceType to 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.
    • alignesWithSearchIndex

      public boolean alignesWithSearchIndex()
      Do ValuesSources built by this config line up with the search index of the underlying field? This'll only return true if the fields is searchable and there aren't missing values or a script to confuse the ordering.
    • getDescription

      public String getDescription()
      Returns a human readable description of this values source, for use in error messages and similar.