Class AggregationContext
java.lang.Object
org.elasticsearch.search.aggregations.support.AggregationContext
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,Releasable
- Direct Known Subclasses:
AggregationContext.ProductionAggregationContext
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 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
Nested Classes Modifier and Type Class Description static class
AggregationContext.ProductionAggregationContext
Implementation of AggregationContext for production usage that wraps our ubiquitousSearchExecutionContext
and anything else specific to aggregations. -
Constructor Summary
Constructors Constructor Description AggregationContext()
-
Method Summary
Modifier and Type Method Description abstract void
addReleasable(Aggregator aggregator)
Cause this aggregation to be released when the search is finished.abstract BigArrays
bigArrays()
Utility to share and track large arrays.abstract BitsetFilterCache
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.FieldContext
buildFieldContext(java.lang.String field)
Lookup the context for a field.FieldContext
buildFieldContext(MappedFieldType ft)
Lookup the context for an already resolved field type.protected abstract IndexFieldData<?>
buildFieldData(MappedFieldType ft)
Build field data.abstract org.apache.lucene.search.Query
buildQuery(QueryBuilder builder)
Build a query.abstract java.util.Optional<SortAndFormats>
buildSort(java.util.List<SortBuilder<?>> sortBuilders)
Compile a sort.abstract <FactoryType>
FactoryTypecompile(Script script, ScriptContext<FactoryType> context)
Compile a script.abstract MappedFieldType
getFieldType(java.lang.String path)
Lookup aMappedFieldType
by path.abstract java.util.Collection<MappedFieldType>
getFieldTypes()
Returns the registered mapped field types.abstract org.apache.lucene.analysis.Analyzer
getIndexAnalyzer(java.util.function.Function<java.lang.String,NamedAnalyzer> unindexedFieldAnalyzer)
Return the index-time analyzer for the current indexabstract IndexSettings
getIndexSettings()
The settings for the index against which this search is running.abstract ObjectMapper
getObjectMapper(java.lang.String path)
Find anObjectMapper
.abstract long
getRelativeTimeInMillis()
How many millis have passed since we started the search?AggregationUsageService
getUsageService()
TheAggregationUsageService
used to track which aggregations are actually used.abstract ValuesSourceRegistry
getValuesSourceRegistry()
TheValuesSourceRegistry
to resolveAggregator
s and the like.abstract Version
indexVersionCreated()
abstract boolean
isCacheable()
Is this request cacheable? Requests that have non-deterministic queries or scripts aren't cachable.abstract boolean
isCancelled()
Has the search been cancelled?abstract boolean
isFieldMapped(java.lang.String field)
Returns true if the field identified by the provided name is mapped, false otherwiseabstract SearchLookup
lookup()
Fetch the sharedSearchLookup
.abstract MultiBucketConsumerService.MultiBucketConsumer
multiBucketConsumer()
abstract NestedScope
nestedScope()
Access the nested scope.abstract long
nowInMillis()
The time in milliseconds that is shared across all resources involved.abstract Aggregator
profileIfEnabled(Aggregator agg)
Wrap the aggregator for profiling if profiling is enabled.abstract boolean
profiling()
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
shardRandomSeed()
Get a deterministic random seed based for this particular shard.abstract SubSearchContext
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.common.lease.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:
java.io.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. -
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
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
public abstract org.apache.lucene.search.Query buildQuery(QueryBuilder builder) throws java.io.IOExceptionBuild a query.- Throws:
java.io.IOException
-
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 java.io.IOExceptionCompile a sort.- Throws:
java.io.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 java.io.IOExceptionBuild a collector for sorted values specialized for aggregations.- Throws:
java.io.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(java.util.function.Function<java.lang.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.
-