Class AggregationContext

java.lang.Object
org.elasticsearch.search.aggregations.support.AggregationContext
All Implemented Interfaces:
Closeable, AutoCloseable, org.elasticsearch.core.Releasable
Direct Known Subclasses:
AggregationContext.ProductionAggregationContext

public abstract class AggregationContext extends Object implements org.elasticsearch.core.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 org.apache.lucene.search.Query query()
      The query at the top level of the search in which these aggregations are running.
    • profileIfEnabled

      public abstract Aggregator profileIfEnabled(Aggregator agg) throws IOException
      Wrap the aggregator for profiling if profiling is enabled.
      Throws:
      IOException
    • 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(String field)
      Lookup the context for a field.
    • getNamedAnalyzer

      public abstract org.apache.lucene.analysis.Analyzer getNamedAnalyzer(String analyzer) throws IOException
      Returns an existing registered analyzer that should NOT be closed when finished being used.
      Parameters:
      analyzer - The custom analyzer name
      Returns:
      The existing named analyzer.
      Throws:
      IOException
    • buildCustomAnalyzer

      public abstract org.apache.lucene.analysis.Analyzer buildCustomAnalyzer(IndexSettings indexSettings, boolean normalizer, NameOrDefinition tokenizer, List<NameOrDefinition> charFilters, List<NameOrDefinition> tokenFilters) throws IOException
      Creates a new custom analyzer that should be closed when finished being used.
      Parameters:
      indexSettings - The current index settings or null
      normalizer - Is a normalizer
      tokenizer - The tokenizer name or definition to use
      charFilters - The char filter name or definition to use
      tokenFilters - The token filter name or definition to use
      Returns:
      A new custom analyzer
      Throws:
      IOException
    • 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(String path)
      Lookup a MappedFieldType by path.
    • getMatchingFieldNames

      public abstract Set<String> getMatchingFieldNames(String pattern)
      Returns a set of field names that match a regex-like pattern All field names in the returned set are guaranteed to resolve to a field
    • isFieldMapped

      public abstract boolean isFieldMapped(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 org.apache.lucene.search.IndexSearcher searcher()
      The searcher that will execute this query.
    • buildQuery

      public abstract org.apache.lucene.search.Query buildQuery(QueryBuilder builder) throws IOException
      Build a query.
      Throws:
      IOException
    • filterQuery

      public abstract org.apache.lucene.search.Query filterQuery(org.apache.lucene.search.Query query)
      Add filters from slice or filtered aliases. If you make a new query and don't combine it with the top level query then you must provide it to this method.
    • getIndexSettings

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

      public abstract Optional<SortAndFormats> buildSort(List<SortBuilder<?>> sortBuilders) throws IOException
      Compile a sort.
      Throws:
      IOException
    • getObjectMapper

      public abstract ObjectMapper getObjectMapper(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 IOException
      Build a collector for sorted values specialized for aggregations.
      Throws:
      IOException
    • 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(Function<String,NamedAnalyzer> unindexedFieldAnalyzer)
      Return the index-time analyzer for the current index
      Parameters:
      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.
    • enableRewriteToFilterByFilter

      public abstract boolean enableRewriteToFilterByFilter()
      Are aggregations allowed to try to rewrite themselves into FilterByFilterAggregator aggregations? Often FilterByFilterAggregator is faster to execute, but it isn't always. For now this just hooks into a cluster level setting so users can disable the behavior when the existing heuristics don't detect cases where its slower.