Module org.elasticsearch.server
Class AggregationContext
java.lang.Object
org.elasticsearch.search.aggregations.support.AggregationContext
- All Implemented Interfaces:
Closeable,AutoCloseable,Releasable
- Direct Known Subclasses:
AggregationContext.ProductionAggregationContext
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.abstract org.apache.lucene.analysis.AnalyzerbuildCustomAnalyzer(IndexSettings indexSettings, boolean normalizer, NameOrDefinition tokenizer, List<NameOrDefinition> charFilters, List<NameOrDefinition> tokenFilters) Creates a new custom analyzer that should be closed when finished being used.final FieldContextbuildFieldContext(String field) Lookup the context for a field.final FieldContextLookup 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 ClusterSettingsThe settings for the cluster against which this search is running.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.Returns the MappingLookup for the index, if one is initialized.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 org.apache.lucene.analysis.AnalyzergetNamedAnalyzer(String analyzer) Returns an existing registered analyzer that should NOT be closed when finished being used.abstract longHow many millis have passed since we started the search?final AggregationUsageServiceTheAggregationUsageServiceused to track which aggregations are actually used.abstract ValuesSourceRegistryTheValuesSourceRegistryto resolveAggregators and the like.final booleanDoes this index have a_doc_countfield in any segment?abstract booleanIs this request cacheable? Requests that have non-deterministic queries or scripts aren't cachable.abstract booleanHas the search been cancelled?abstract booleanReturn true if any of the aggregations in this context is a time-series aggregation that requires an in-sort order execution.abstract SearchLookuplookup()Fetch the sharedSearchLookup.abstract intMax buckets provided by the search.max_buckets settingabstract NestedLookupGet theNestedLookupof this indexabstract 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 voidremoveReleasable(Aggregator aggregator) Cause this aggregation to be released when the search is finished.abstract org.apache.lucene.search.IndexSearchersearcher()The searcher that will execute this query.abstract intGet a deterministic random seed based for this particular shard.sourcePath(String fullName) 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. -
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 nullnormalizer- Is a normalizertokenizer- The tokenizer name or definition to usecharFilters- The char filter name or definition to usetokenFilters- The token filter name or definition to use- Returns:
- A new custom analyzer
- Throws:
IOException
-
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 -
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. -
getClusterSettings
The settings for the cluster against which this search is running. -
buildSort
public abstract Optional<SortAndFormats> buildSort(List<SortBuilder<?>> sortBuilders) throws IOException Compile a sort.- Throws:
IOException
-
nestedLookup
Get theNestedLookupof this index -
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. -
removeReleasable
Cause this aggregation to be released when the search is finished. -
maxBuckets
public abstract int maxBuckets()Max buckets provided by the search.max_buckets setting -
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
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
-
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. -
isInSortOrderExecutionRequired
public abstract boolean isInSortOrderExecutionRequired()Return true if any of the aggregations in this context is a time-series aggregation that requires an in-sort order execution. A side-effect of such execution is that all leaves are walked simultaneously and therefore we can no longer rely onBucketCollector.getLeafCollector(AggregationExecutionContext)to be called only after the previous leaf was fully collected. -
sourcePath
-
getMappingLookup
Returns the MappingLookup for the index, if one is initialized. -
hasDocCountField
Does this index have a_doc_countfield in any segment?- Throws:
IOException
-