Module org.elasticsearch.server
Class AggregationBuilder
java.lang.Object
org.elasticsearch.search.aggregations.AggregationBuilder
- All Implemented Interfaces:
NamedWriteable
,VersionedNamedWriteable
,Writeable
,Rewriteable<AggregationBuilder>
,BaseAggregationBuilder
,ToXContent
,ToXContentFragment
- Direct Known Subclasses:
AbstractAggregationBuilder
public abstract class AggregationBuilder
extends Object
implements VersionedNamedWriteable, ToXContentFragment, BaseAggregationBuilder, Rewriteable<AggregationBuilder>
A factory that knows how to create an
Aggregator
of a specific type.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
A rough count of the number of buckets thatAggregator
s built by this builder will contain per parent bucket used to validate sorts and pipeline aggregations.static final class
Common xcontent fields shared among aggregator buildersNested classes/interfaces inherited from interface org.elasticsearch.xcontent.ToXContent
ToXContent.DelegatingMapParams, ToXContent.MapParams, ToXContent.Params
Nested classes/interfaces inherited from interface org.elasticsearch.common.io.stream.Writeable
Writeable.Reader<V>, Writeable.Writer<V>
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final long
protected AggregatorFactories.Builder
protected final String
Fields inherited from interface org.elasticsearch.index.query.Rewriteable
MAX_REWRITE_ROUNDS
Fields inherited from interface org.elasticsearch.xcontent.ToXContent
EMPTY, EMPTY_PARAMS
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AggregationBuilder
(String name) Constructs a new aggregation builder.protected
AggregationBuilder
(AggregationBuilder clone, AggregatorFactories.Builder factoriesBuilder) -
Method Summary
Modifier and TypeMethodDescriptionabstract AggregationBuilder.BucketCardinality
A rough count of the number of buckets thatAggregator
s built by this builder will contain per owning parent bucket.protected abstract AggregatorFactory
build
(AggregationContext context, AggregatorFactory parent) Internal: build anAggregatorFactory
based on the configuration of this builder.Build a tree ofPipelineAggregator
s to modify the tree of aggregation results after the final reduction.long
Bytes to preallocate on the "request" breaker for this aggregation.static AggregationBuilder
deepCopy
(AggregationBuilder original, Function<AggregationBuilder, AggregationBuilder> visitor) Creates a deep copy of by recursively invoking#shallowCopy
on the sub aggregations.protected AggregationBuilder
doRewrite
(QueryRewriteContext queryRewriteContext) Rewrites this aggregation builder into its primitive form.Return any associated metadata with thisAggregationBuilder
.getName()
Return this aggregation's name.Return the field names this aggregation creates.Return the configured set of pipeline aggregationsgetQuery()
Return the aggregation's query if it's different from the search query, or null otherwise.Return the configured set of subaggregationsboolean
Return true if any of the child aggregations is a time-series aggregation that requires an in-order executionfinal AggregationBuilder
rewrite
(QueryRewriteContext context) Rewrites this instance based on the provided context.abstract AggregationBuilder
setMetadata
(Map<String, Object> metadata) Associate metadata with thisAggregationBuilder
.protected abstract AggregationBuilder
shallowCopy
(AggregatorFactories.Builder factoriesBuilder, Map<String, Object> metadata) Create a shallow copy of this builder and replacingfactoriesBuilder
andmetadata
.abstract AggregationBuilder
subAggregation
(AggregationBuilder aggregation) Add a sub aggregation to this builder.abstract AggregationBuilder
subAggregation
(PipelineAggregationBuilder aggregation) Add a sub aggregation to this builder.abstract AggregationBuilder
subAggregations
(AggregatorFactories.Builder subFactories) Internal: Registers sub-factories with this factory.boolean
supportsParallelCollection
(ToLongFunction<String> fieldCardinalityResolver) Return false if this aggregation or any of the child aggregations does not support parallel collection.boolean
Does this aggregation support running with in a sampling context.toString()
protected void
validateSequentiallyOrdered
(String type, String name, Consumer<String> addValidationError) Called by aggregations whose parents must be sequentially ordered.protected void
validateSequentiallyOrderedWithoutGaps
(String type, String name, Consumer<String> addValidationError) Called by aggregations whose parents must be sequentially ordered without any gaps.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.elasticsearch.search.aggregations.BaseAggregationBuilder
getType
Methods inherited from interface org.elasticsearch.xcontent.ToXContent
toXContent
Methods inherited from interface org.elasticsearch.xcontent.ToXContentFragment
isFragment
Methods inherited from interface org.elasticsearch.common.io.stream.VersionedNamedWriteable
getMinimalSupportedVersion, getWriteableName
-
Field Details
-
DEFAULT_PREALLOCATION
public static final long DEFAULT_PREALLOCATION- See Also:
-
name
-
factoriesBuilder
-
-
Constructor Details
-
AggregationBuilder
Constructs a new aggregation builder.- Parameters:
name
- The aggregation name
-
AggregationBuilder
protected AggregationBuilder(AggregationBuilder clone, AggregatorFactories.Builder factoriesBuilder)
-
-
Method Details
-
getName
Return this aggregation's name. -
getOutputFieldNames
Return the field names this aggregation creates. This method is a optional helper for clients that need to know the output field names.- Returns:
- The set of output field names this aggregation produces or Optional.empty() if not implemented or Optional.of(emptySet()) if the fields are not known.
-
build
protected abstract AggregatorFactory build(AggregationContext context, AggregatorFactory parent) throws IOException Internal: build anAggregatorFactory
based on the configuration of this builder.- Throws:
IOException
-
setMetadata
Associate metadata with thisAggregationBuilder
.- Specified by:
setMetadata
in interfaceBaseAggregationBuilder
-
getMetadata
Return any associated metadata with thisAggregationBuilder
. -
subAggregation
Add a sub aggregation to this builder. -
subAggregation
Add a sub aggregation to this builder. -
getSubAggregations
Return the configured set of subaggregations -
getQuery
Return the aggregation's query if it's different from the search query, or null otherwise. -
getPipelineAggregations
Return the configured set of pipeline aggregations -
subAggregations
Internal: Registers sub-factories with this factory. The sub-factory will be responsible for the creation of sub-aggregators under the aggregator created by this factory. This is only for use byAggregatorFactories.parseAggregators(XContentParser)
.- Specified by:
subAggregations
in interfaceBaseAggregationBuilder
- Parameters:
subFactories
- The sub-factories- Returns:
- this factory (fluent interface)
-
shallowCopy
protected abstract AggregationBuilder shallowCopy(AggregatorFactories.Builder factoriesBuilder, Map<String, Object> metadata) Create a shallow copy of this builder and replacingfactoriesBuilder
andmetadata
. -
deepCopy
public static AggregationBuilder deepCopy(AggregationBuilder original, Function<AggregationBuilder, AggregationBuilder> visitor) Creates a deep copy of by recursively invoking#shallowCopy
on the sub aggregations. Each copied agg is passed through the function that returns a possibly modified "copy". -
rewrite
Description copied from interface:Rewriteable
Rewrites this instance based on the provided context. The returned objects will be the same instance as this if no changes during the rewrite were applied.- Specified by:
rewrite
in interfaceRewriteable<AggregationBuilder>
- Throws:
IOException
-
doRewrite
Rewrites this aggregation builder into its primitive form. By default this method return the builder itself. If the builder did not change the identity reference must be returned otherwise the builder will be rewritten infinitely.- Throws:
IOException
-
buildPipelineTree
Build a tree ofPipelineAggregator
s to modify the tree of aggregation results after the final reduction. -
bucketCardinality
A rough count of the number of buckets thatAggregator
s built by this builder will contain per owning parent bucket. -
bytesToPreallocate
public long bytesToPreallocate()Bytes to preallocate on the "request" breaker for this aggregation. The goal is to request a few more bytes than we expect to use at first to cut down on contention on the "request" breaker when we are constructing the aggs. Underestimating what we allocate up front will fail to accomplish the goal. Overestimating will cause requests to fail for no reason. -
supportsSampling
public boolean supportsSampling()Does this aggregation support running with in a sampling context. By default, it's false for all aggregations. If the sub-classed builder supports sampling, be sure of the following that the resulting internal aggregation objects override theInternalAggregation.finalizeSampling(SamplingContext)
and scales any values that require scaling.- Returns:
- does this aggregation builder support sampling
-
toString
-
isInSortOrderExecutionRequired
public boolean isInSortOrderExecutionRequired()Return true if any of the child aggregations is a time-series aggregation that requires an in-order execution -
supportsParallelCollection
Return false if this aggregation or any of the child aggregations does not support parallel collection. As a result, a request including such aggregation is always executed sequentially despite concurrency is enabled for the query phase. -
validateSequentiallyOrdered
protected void validateSequentiallyOrdered(String type, String name, Consumer<String> addValidationError) Called by aggregations whose parents must be sequentially ordered.- Parameters:
type
- the type of the aggregation being validatedname
- the name of the aggregation being validatedaddValidationError
- callback to add validation errors
-
validateSequentiallyOrderedWithoutGaps
protected void validateSequentiallyOrderedWithoutGaps(String type, String name, Consumer<String> addValidationError) Called by aggregations whose parents must be sequentially ordered without any gaps.- Parameters:
type
- the type of the aggregation being validatedname
- the name of the aggregation being validatedaddValidationError
- callback to add validation errors
-