Class AggregatorBase
- All Implemented Interfaces:
Closeable
,AutoCloseable
,org.apache.lucene.search.Collector
,org.elasticsearch.core.Releasable
- Direct Known Subclasses:
BucketsAggregator
,MetricsAggregator
,NonCollectingAggregator
-
Nested Class Summary
Nested classes/interfaces inherited from class org.elasticsearch.search.aggregations.Aggregator
Aggregator.BucketComparator, Aggregator.Parser, Aggregator.SubAggCollectionMode
-
Field Summary
Modifier and TypeFieldDescriptionprotected BucketCollector
static final int
The default "weight" that a bucket takes when performing an aggregationprotected final String
protected final Aggregator
protected final Aggregator[]
Fields inherited from class org.elasticsearch.search.aggregations.BucketCollector
NO_OP_COLLECTOR
-
Constructor Summary
ModifierConstructorDescriptionprotected
AggregatorBase
(String name, AggregatorFactories factories, AggregationContext context, Aggregator parent, CardinalityUpperBound subAggregatorCardinality, Map<String, Object> metadata) Constructs a new Aggregator. -
Method Summary
Modifier and TypeMethodDescriptionprotected long
addRequestCircuitBreakerBytes
(long bytes) Increment or decrement the number of bytes that have been allocated to service this request and potentially trigger aCircuitBreakingException
.protected final BigArrays
Utilities for sharing large primitive arrays and tracking their usage.protected final InternalAggregations
void
close()
Called upon release of the aggregator.protected void
doClose()
Release instance-specific data.protected void
Can be overridden by aggregator implementation to be called back when the collection phase ends.protected void
Can be overridden by aggregator implementation to be called back when the collection phase starts.final LeafBucketCollector
getLeafCollector
(org.apache.lucene.index.LeafReaderContext ctx) Collect results for this leaf.protected abstract LeafBucketCollector
getLeafCollector
(org.apache.lucene.index.LeafReaderContext ctx, LeafBucketCollector sub) Collect results for this leaf.metadata()
name()
Return the name of this aggregator.parent()
Return the parent aggregator.Returns a converter for point values if it's safe to use the indexed data instead of doc values.void
Called after collection of all document is done.final void
Pre collection callback.protected void
preGetSubLeafCollectors
(org.apache.lucene.index.LeafReaderContext ctx) 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.ScoreMode
Most aggregators don't need scores, make sure to extend this method if your aggregator needs them.protected final org.apache.lucene.search.IndexSearcher
searcher()
The searcher for the shard this Aggregator is running against.subAggregator
(String aggName) Return the sub aggregator with the provided name.Get the aggregators running under this one.protected final org.apache.lucene.search.Query
The "top level" query that will filter the results sent to this Aggregator.toString()
Methods inherited from class org.elasticsearch.search.aggregations.Aggregator
bucketComparator, buildAggregations, buildEmptyAggregation, buildTopLevel, collectDebugInfo, resolveSortPath, resolveSortPathOnValidAgg
-
Field Details
-
DEFAULT_WEIGHT
public static final int DEFAULT_WEIGHTThe default "weight" that a bucket takes when performing an aggregation- See Also:
-
name
-
parent
-
subAggregators
-
collectableSubAggregators
-
-
Constructor Details
-
AggregatorBase
protected AggregatorBase(String name, AggregatorFactories factories, AggregationContext context, Aggregator parent, CardinalityUpperBound subAggregatorCardinality, Map<String, Object> metadata) throws 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 benull
for top level aggregators)subAggregatorCardinality
- Upper bound of the number of buckets that sub aggregations will collectmetadata
- The metadata associated with this aggregator- Throws:
IOException
-
-
Method Details
-
pointReaderIfAvailable
Returns a converter for point values if it's safe to use the indexed data instead of doc values. Generally, this means that the query has no filters or scripts, the aggregation is top level, and the underlying field is indexed, and the index is sorted in the right order. If those conditions aren't met, returnnull
to indicate a point reader cannot be used in this case.- Parameters:
config
- The config for the values source metric.
-
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
-
getLeafCollector
protected abstract LeafBucketCollector getLeafCollector(org.apache.lucene.index.LeafReaderContext ctx, LeafBucketCollector sub) throws IOException Collect results for this leaf.Most Aggregators will return a custom
LeafBucketCollector
that collects document information for every hit. Callers of this method will make sure to callcollect
for every hit. So anyAggregator
that returns a customer LeafBucketCollector from this method runs at bestO(hits)
time. See thesum
Aggregator for a fairly strait forward example of this.Some Aggregators are able to correctly collect results on their own, without being iterated by the top level query or the rest of the aggregations framework. These aggregations collect what they need by calling methods on
LeafReaderContext
and then they returnLeafBucketCollector.NO_OP_COLLECTOR
to signal that they've done their own collection. These aggregations can do better thanO(hits)
. See themin
Aggregator for an example of an aggregation that does this. It happens to run in constant time in some cases.In other cases
MinAggregator
can't get correct results by taking the constant time path so instead it returns a customLeafBucketCollector
. This is fairly common for aggregations that have these fast paths because most of these fast paths are only possible when the aggregation is at the root of the tree.Its also useful to look at the
filters
Aggregator chooses whether or not it can use the fast path before building the Aggregator rather than on each leaf. Either is fine.- Throws:
IOException
-
getLeafCollector
public final LeafBucketCollector getLeafCollector(org.apache.lucene.index.LeafReaderContext ctx) throws IOException Collect results for this leaf.Implemented by the Aggregator base class to correctly set up sub Aggregators. See the
abstract delegate
for more details on what this does.- Specified by:
getLeafCollector
in interfaceorg.apache.lucene.search.Collector
- Specified by:
getLeafCollector
in classBucketCollector
- Throws:
IOException
-
preGetSubLeafCollectors
protected void preGetSubLeafCollectors(org.apache.lucene.index.LeafReaderContext ctx) throws IOException 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.- Throws:
IOException
-
doPreCollection
Can be overridden by aggregator implementation to be called back when the collection phase starts.- Throws:
IOException
-
preCollection
Description copied from class:BucketCollector
Pre collection callback.- Specified by:
preCollection
in classBucketCollector
- Throws:
IOException
-
name
Description copied from class:Aggregator
Return the name of this aggregator.- Specified by:
name
in classAggregator
- Returns:
- The name of the aggregation.
-
parent
Description copied from class:Aggregator
Return the parent aggregator.- Specified by:
parent
in 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
null
if there is none (meaning, this aggregator is a top level one)
-
subAggregators
Description copied from class:Aggregator
Get the aggregators running under this one.- Specified by:
subAggregators
in classAggregator
-
subAggregator
Description copied from class:Aggregator
Return the sub aggregator with the provided name.- Specified by:
subAggregator
in classAggregator
-
postCollection
Called after collection of all document is done.Warning: this is not final only to allow the parent join aggregator to delay this until building buckets.
- Specified by:
postCollection
in classBucketCollector
- Throws:
IOException
-
close
public void close()Called upon release of the aggregator. -
doClose
protected void doClose()Release instance-specific data. -
doPostCollection
Can be overridden by aggregator implementation to be called back when the collection phase ends.- Throws:
IOException
-
buildEmptySubAggregations
-
toString
-
bigArrays
Utilities for sharing large primitive arrays and tracking their usage. Used by all subclasses. -
topLevelQuery
protected final org.apache.lucene.search.Query topLevelQuery()The "top level" query that will filter the results sent to this Aggregator. Used by all Aggregators that perform extra collection phases in addition to the one done ingetLeafCollector(LeafReaderContext, LeafBucketCollector)
. -
searcher
protected final org.apache.lucene.search.IndexSearcher searcher()The searcher for the shard this Aggregator is running against. Used by all Aggregators that perform extra collection phases in addition to the one done ingetLeafCollector(LeafReaderContext, LeafBucketCollector)
and by to look up extra "background" information about contents of the shard itself.
-