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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classImplementation of AggregationContext for production usage that wraps our ubiquitousSearchExecutionContextand anything else specific to aggregations. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract voidaddReleasable(Aggregator aggregator)Cause this aggregation to be released when the search is finished.abstract BigArraysUtility to share and track large arrays.abstract BitsetFilterCacheGet the filter cache.abstract CircuitBreakerbreaker()The circuit breaker used to account for aggs.abstract BucketedSortbuildBucketedSort(SortBuilder<?> sort, int size, BucketedSort.ExtraData values)Build a collector for sorted values specialized for aggregations.buildFieldContext(String field)Lookup the context for a field.Lookup the context for an already resolved field type.protected abstract IndexFieldData<?>Build field data.abstract org.apache.lucene.search.QuerybuildQuery(QueryBuilder builder)Build a query.abstract Optional<SortAndFormats>buildSort(List<SortBuilder<?>> sortBuilders)Compile a sort.abstract <FactoryType>
FactoryTypecompile(Script script, ScriptContext<FactoryType> context)Compile a script.abstract booleanAre aggregations allowed to try to rewrite themselves intoFilterByFilterAggregatoraggregations? Often FilterByFilterAggregator is faster to execute, but it isn't always.abstract org.apache.lucene.search.QueryfilterQuery(org.apache.lucene.search.Query query)Add filters from slice or filtered aliases.abstract MappedFieldTypegetFieldType(String path)Lookup aMappedFieldTypeby path.abstract org.apache.lucene.analysis.AnalyzergetIndexAnalyzer(Function<String,NamedAnalyzer> unindexedFieldAnalyzer)Return the index-time analyzer for the current indexabstract IndexSettingsThe settings for the index against which this search is running.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 fieldabstract ObjectMappergetObjectMapper(String path)Find anObjectMapper.abstract longHow many millis have passed since we started the search?TheAggregationUsageServiceused to track which aggregations are actually used.abstract ValuesSourceRegistryTheValuesSourceRegistryto resolveAggregators and the like.abstract Versionabstract booleanIs this request cacheable? Requests that have non-deterministic queries or scripts aren't cachable.abstract booleanHas the search been cancelled?abstract booleanisFieldMapped(String field)Returns true if the field identified by the provided name is mapped, false otherwiseabstract SearchLookuplookup()Fetch the sharedSearchLookup.abstract NestedScopeAccess the nested scope.abstract longThe time in milliseconds that is shared across all resources involved.abstract AggregatorWrap the aggregator for profiling if profiling is enabled.abstract booleanAre we profiling the aggregation?abstract org.apache.lucene.search.Queryquery()The query at the top level of the search in which these aggregations are running.abstract org.apache.lucene.search.IndexSearchersearcher()The searcher that will execute this query.abstract intGet a deterministic random seed based for this particular shard.abstract SubSearchContextBuild a SubSearchContext to power an aggregation fetching top hits.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.elasticsearch.core.Releasable
close
-
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
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
Lookup the context for a field. -
buildFieldContext
Lookup the context for an already resolved field type. -
buildFieldData
Build field data. -
getFieldType
Lookup aMappedFieldTypeby path. -
getMatchingFieldNames
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
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
Fetch the sharedSearchLookup. -
getValuesSourceRegistry
TheValuesSourceRegistryto resolveAggregators and the like. -
getUsageService
TheAggregationUsageServiceused to track which aggregations are actually used. -
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
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 thetop level querythen you must provide it to this method. -
getIndexSettings
The settings for the index against which this search is running. -
buildSort
public abstract Optional<SortAndFormats> buildSort(List<SortBuilder<?>> sortBuilders) throws IOExceptionCompile a sort.- Throws:
IOException
-
getObjectMapper
Find anObjectMapper. -
nestedScope
Access the nested scope. Stay away from this unless you are dealing with nested. -
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
Cause this aggregation to be released when the search is finished. -
multiBucketConsumer
-
bitsetFilterCache
Get the filter cache. -
buildBucketedSort
public abstract BucketedSort buildBucketedSort(SortBuilder<?> sort, int size, BucketedSort.ExtraData values) throws IOExceptionBuild 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
volatileread. -
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
-
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 intoFilterByFilterAggregatoraggregations? 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.
-