Class AggregationContext

All Implemented Interfaces:, java.lang.AutoCloseable, Releasable
Direct Known Subclasses:

public abstract class AggregationContext
extends java.lang.Object
implements Releasable
Everything used to build and execute aggregations and the data sources that power them.

In production we always use the AggregationContext.ProductionAggregationContext but this is abstract so that tests can build it without creating the massing SearchExecutionContext.

AggregationContexts are Releasable because they track the Aggregators they build and Releasable.close() them when the request is done. AggregationContext may also preallocate bytes on the "REQUEST" breaker and is responsible for releasing those bytes.

  • Constructor Details

    • AggregationContext

      public AggregationContext()
  • Method Details

    • query

      public abstract query()
      The query at the top level of the search in which these aggregations are running.
    • profileIfEnabled

      public abstract Aggregator profileIfEnabled​(Aggregator agg) throws
      Wrap the aggregator for profiling if profiling is enabled.
    • profiling

      public abstract boolean profiling()
      Are we profiling the aggregation?
    • nowInMillis

      public abstract long nowInMillis()
      The time in milliseconds that is shared across all resources involved. Even across shards and nodes.
    • buildFieldContext

      public final FieldContext buildFieldContext​(java.lang.String field)
      Lookup the context for a field.
    • buildFieldContext

      public final FieldContext buildFieldContext​(MappedFieldType ft)
      Lookup the context for an already resolved field type.
    • buildFieldData

      protected abstract IndexFieldData<?> buildFieldData​(MappedFieldType ft)
      Build field data.
    • getFieldType

      public abstract MappedFieldType getFieldType​(java.lang.String path)
      Lookup a MappedFieldType by path.
    • getFieldTypes

      public abstract java.util.Collection<MappedFieldType> getFieldTypes()
      Returns the registered mapped field types.
    • isFieldMapped

      public abstract boolean isFieldMapped​(java.lang.String field)
      Returns true if the field identified by the provided name is mapped, false otherwise
    • compile

      public abstract <FactoryType> FactoryType compile​(Script script, ScriptContext<FactoryType> context)
      Compile a script.
    • lookup

      public abstract SearchLookup lookup()
      Fetch the shared SearchLookup.
    • getValuesSourceRegistry

      public abstract ValuesSourceRegistry getValuesSourceRegistry()
      The ValuesSourceRegistry to resolve Aggregators and the like.
    • getUsageService

      public final AggregationUsageService getUsageService()
      The AggregationUsageService used to track which aggregations are actually used.
    • bigArrays

      public abstract BigArrays bigArrays()
      Utility to share and track large arrays.
    • searcher

      public abstract searcher()
      The searcher that will execute this query.
    • buildQuery

      public abstract buildQuery​(QueryBuilder builder) throws
      Build a query.
    • getIndexSettings

      public abstract IndexSettings getIndexSettings()
      The settings for the index against which this search is running.
    • buildSort

      public abstract java.util.Optional<SortAndFormats> buildSort​(java.util.List<SortBuilder<?>> sortBuilders) throws
      Compile a sort.
    • getObjectMapper

      public abstract ObjectMapper getObjectMapper​(java.lang.String path)
      Find an ObjectMapper.
    • nestedScope

      public abstract NestedScope nestedScope()
      Access the nested scope. Stay away from this unless you are dealing with nested.
    • subSearchContext

      public abstract SubSearchContext subSearchContext()
      Build a SubSearchContext to power an aggregation fetching top hits. Try to avoid using this because it pulls in a ton of dependencies.
    • addReleasable

      public abstract void addReleasable​(Aggregator aggregator)
      Cause this aggregation to be released when the search is finished.
    • multiBucketConsumer

      public abstract MultiBucketConsumerService.MultiBucketConsumer multiBucketConsumer()
    • bitsetFilterCache

      public abstract BitsetFilterCache bitsetFilterCache()
      Get the filter cache.
    • buildBucketedSort

      public abstract BucketedSort buildBucketedSort​(SortBuilder<?> sort, int size, BucketedSort.ExtraData values) throws
      Build a collector for sorted values specialized for aggregations.
    • shardRandomSeed

      public abstract int shardRandomSeed()
      Get a deterministic random seed based for this particular shard.
    • getRelativeTimeInMillis

      public abstract long getRelativeTimeInMillis()
      How many millis have passed since we started the search?
    • isCancelled

      public abstract boolean isCancelled()
      Has the search been cancelled?

      This'll require a volatile read.

    • breaker

      public abstract CircuitBreaker breaker()
      The circuit breaker used to account for aggs.
    • getIndexAnalyzer

      public abstract org.apache.lucene.analysis.Analyzer getIndexAnalyzer​(java.util.function.Function<java.lang.String,​NamedAnalyzer> unindexedFieldAnalyzer)
      Return the index-time analyzer for the current index
      unindexedFieldAnalyzer - a function that builds an analyzer for unindexed fields
    • indexVersionCreated

      public abstract Version indexVersionCreated()
    • isCacheable

      public abstract boolean isCacheable()
      Is this request cacheable? Requests that have non-deterministic queries or scripts aren't cachable.