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 Aggregator
s 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
Modifier and TypeClassDescriptionstatic class
Implementation of AggregationContext for production usage that wraps our ubiquitousSearchExecutionContext
and anything else specific to aggregations. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionabstract void
addReleasable(Aggregator aggregator)
Cause this aggregation to be released when the search is finished.abstract BigArrays
Utility to share and track large arrays.abstract BitsetFilterCache
Get the filter cache.abstract CircuitBreaker
breaker()
The circuit breaker used to account for aggs.abstract BucketedSort
buildBucketedSort(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.Query
buildQuery(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 boolean
Are aggregations allowed to try to rewrite themselves intoFilterByFilterAggregator
aggregations? Often FilterByFilterAggregator is faster to execute, but it isn't always.abstract org.apache.lucene.search.Query
filterQuery(org.apache.lucene.search.Query query)
Add filters from slice or filtered aliases.abstract MappedFieldType
getFieldType(String path)
Lookup aMappedFieldType
by path.abstract org.apache.lucene.analysis.Analyzer
getIndexAnalyzer(Function<String,NamedAnalyzer> unindexedFieldAnalyzer)
Return the index-time analyzer for the current indexabstract IndexSettings
The 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 ObjectMapper
getObjectMapper(String path)
Find anObjectMapper
.abstract long
How many millis have passed since we started the search?TheAggregationUsageService
used to track which aggregations are actually used.abstract ValuesSourceRegistry
TheValuesSourceRegistry
to resolveAggregator
s and the like.abstract Version
abstract boolean
Is this request cacheable? Requests that have non-deterministic queries or scripts aren't cachable.abstract boolean
Has the search been cancelled?abstract boolean
isFieldMapped(String field)
Returns true if the field identified by the provided name is mapped, false otherwiseabstract SearchLookup
lookup()
Fetch the sharedSearchLookup
.abstract NestedScope
Access the nested scope.abstract long
The time in milliseconds that is shared across all resources involved.abstract Aggregator
Wrap the aggregator for profiling if profiling is enabled.abstract boolean
Are we profiling the aggregation?abstract org.apache.lucene.search.Query
query()
The query at the top level of the search in which these aggregations are running.abstract org.apache.lucene.search.IndexSearcher
searcher()
The searcher that will execute this query.abstract int
Get a deterministic random seed based for this particular shard.abstract SubSearchContext
Build 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, wait
Methods 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 aMappedFieldType
by 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
TheValuesSourceRegistry
to resolveAggregator
s and the like. -
getUsageService
TheAggregationUsageService
used 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 query
then 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
volatile
read. -
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 intoFilterByFilterAggregator
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.
-