Class AggregatorBase
java.lang.Object
org.elasticsearch.search.aggregations.BucketCollector
org.elasticsearch.search.aggregations.Aggregator
org.elasticsearch.search.aggregations.AggregatorBase
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,org.apache.lucene.search.Collector,Releasable
- Direct Known Subclasses:
BucketsAggregator,MetricsAggregator,NonCollectingAggregator
public abstract class AggregatorBase extends Aggregator
Base implementation for concrete aggregators.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.elasticsearch.search.aggregations.Aggregator
Aggregator.Parser, Aggregator.SubAggCollectionMode -
Field Summary
Fields Modifier and Type Field Description protected BucketCollectorcollectableSubAggregatorsprotected SearchContextcontextstatic intDEFAULT_WEIGHTThe default "weight" that a bucket takes when performing an aggregationprotected java.lang.Stringnameprotected Aggregatorparentprotected Aggregator[]subAggregators -
Constructor Summary
Constructors Modifier Constructor Description protectedAggregatorBase(java.lang.String name, AggregatorFactories factories, SearchContext context, Aggregator parent, java.util.List<PipelineAggregator> pipelineAggregators, java.util.Map<java.lang.String,java.lang.Object> metaData)Constructs a new Aggregator. -
Method Summary
Modifier and Type Method Description protected longaddRequestCircuitBreakerBytes(long bytes)Increment or decrement the number of bytes that have been allocated to service this request and potentially trigger aCircuitBreakingException.protected InternalAggregationsbuildEmptySubAggregations()voidclose()Called upon release of the aggregator.SearchContextcontext()Return theSearchContextattached with thisAggregator.protected voiddoClose()Release instance-specific data.protected voiddoPostCollection()Can be overridden by aggregator implementation to be called back when the collection phase ends.protected voiddoPreCollection()Can be overridden by aggregator implementation to be called back when the collection phase starts.LeafBucketCollectorgetLeafCollector(org.apache.lucene.index.LeafReaderContext ctx)protected abstract LeafBucketCollectorgetLeafCollector(org.apache.lucene.index.LeafReaderContext ctx, LeafBucketCollector sub)Get aLeafBucketCollectorfor the given ctx, which should delegate to the given collector.java.util.Map<java.lang.String,java.lang.Object>metaData()java.lang.Stringname()Return the name of this aggregator.Aggregatorparent()Return the parent aggregator.java.util.List<PipelineAggregator>pipelineAggregators()voidpostCollection()Called after collection of all document is done.voidpreCollection()Pre collection callback.protected voidpreGetSubLeafCollectors()Can be overridden by aggregator implementations that like the perform an operation before the leaf collectors of children aggregators are instantiated for the next segment.org.apache.lucene.search.ScoreModescoreMode()Most aggregators don't need scores, make sure to extend this method if your aggregator needs them.AggregatorsubAggregator(java.lang.String aggName)Return the sub aggregator with the provided name.Aggregator[]subAggregators()java.lang.StringtoString()Methods inherited from class org.elasticsearch.search.aggregations.Aggregator
buildAggregation, buildEmptyAggregation, descendsFromBucketAggregator
-
Field Details
-
DEFAULT_WEIGHT
public static final int DEFAULT_WEIGHTThe default "weight" that a bucket takes when performing an aggregation- See Also:
- Constant Field Values
-
name
protected final java.lang.String name -
parent
-
context
-
subAggregators
-
collectableSubAggregators
-
-
Constructor Details
-
AggregatorBase
protected AggregatorBase(java.lang.String name, AggregatorFactories factories, SearchContext context, Aggregator parent, java.util.List<PipelineAggregator> pipelineAggregators, java.util.Map<java.lang.String,java.lang.Object> metaData) throws java.io.IOExceptionConstructs a new Aggregator.- Parameters:
name- The name of the aggregationfactories- The factories for all the sub-aggregators under this aggregatorcontext- The aggregation contextparent- The parent aggregator (may benullfor top level aggregators)metaData- The metaData associated with this aggregator- Throws:
java.io.IOException
-
-
Method Details
-
addRequestCircuitBreakerBytes
protected long addRequestCircuitBreakerBytes(long bytes)Increment or decrement the number of bytes that have been allocated to service this request and potentially trigger aCircuitBreakingException. The number of bytes allocated is automatically decremented with the circuit breaker service on closure of this aggregator. If memory has been returned, decrement it without tripping the breaker. For performance reasons subclasses should not call this millions of times each with small increments and instead batch up into larger allocations.- Parameters:
bytes- the number of bytes to register or negative to deregister the bytes- Returns:
- the cumulative size in bytes allocated by this aggregator to service this request
-
scoreMode
public org.apache.lucene.search.ScoreMode scoreMode()Most aggregators don't need scores, make sure to extend this method if your aggregator needs them. -
metaData
public java.util.Map<java.lang.String,java.lang.Object> metaData() -
pipelineAggregators
-
getLeafCollector
protected abstract LeafBucketCollector getLeafCollector(org.apache.lucene.index.LeafReaderContext ctx, LeafBucketCollector sub) throws java.io.IOExceptionGet aLeafBucketCollectorfor the given ctx, which should delegate to the given collector.- Throws:
java.io.IOException
-
getLeafCollector
public final LeafBucketCollector getLeafCollector(org.apache.lucene.index.LeafReaderContext ctx) throws java.io.IOException- Specified by:
getLeafCollectorin interfaceorg.apache.lucene.search.Collector- Specified by:
getLeafCollectorin classBucketCollector- Throws:
java.io.IOException
-
preGetSubLeafCollectors
protected void preGetSubLeafCollectors() throws java.io.IOExceptionCan be overridden by aggregator implementations that like the perform an operation before the leaf collectors of children aggregators are instantiated for the next segment.- Throws:
java.io.IOException
-
doPreCollection
protected void doPreCollection() throws java.io.IOExceptionCan be overridden by aggregator implementation to be called back when the collection phase starts.- Throws:
java.io.IOException
-
preCollection
public final void preCollection() throws java.io.IOExceptionDescription copied from class:BucketCollectorPre collection callback.- Specified by:
preCollectionin classBucketCollector- Throws:
java.io.IOException
-
name
public java.lang.String name()Description copied from class:AggregatorReturn the name of this aggregator.- Specified by:
namein classAggregator- Returns:
- The name of the aggregation.
-
parent
Description copied from class:AggregatorReturn the parent aggregator.- Specified by:
parentin classAggregator- Returns:
- The parent aggregator of this aggregator. The addAggregation are hierarchical in the sense that some can
be composed out of others (more specifically, bucket addAggregation can define other addAggregation that will
be aggregated per bucket). This method returns the direct parent aggregator that contains this aggregator, or
nullif there is none (meaning, this aggregator is a top level one)
-
subAggregators
-
subAggregator
Description copied from class:AggregatorReturn the sub aggregator with the provided name.- Specified by:
subAggregatorin classAggregator
-
context
Description copied from class:AggregatorReturn theSearchContextattached with thisAggregator.- Specified by:
contextin classAggregator- Returns:
- The current aggregation context.
-
postCollection
public final void postCollection() throws java.io.IOExceptionCalled after collection of all document is done.- Specified by:
postCollectionin classBucketCollector- Throws:
java.io.IOException
-
close
public void close()Called upon release of the aggregator. -
doClose
protected void doClose()Release instance-specific data. -
doPostCollection
protected void doPostCollection() throws java.io.IOExceptionCan be overridden by aggregator implementation to be called back when the collection phase ends.- Throws:
java.io.IOException
-
buildEmptySubAggregations
-
toString
public java.lang.String toString()- Overrides:
toStringin classjava.lang.Object
-