Class AggregationBuilder
java.lang.Object
org.elasticsearch.search.aggregations.AggregationBuilder
- All Implemented Interfaces:
 NamedWriteable,Writeable,org.elasticsearch.common.xcontent.ToXContent,org.elasticsearch.common.xcontent.ToXContentFragment,Rewriteable<AggregationBuilder>,BaseAggregationBuilder
- Direct Known Subclasses:
 AbstractAggregationBuilder
public abstract class AggregationBuilder
extends Object
implements NamedWriteable, org.elasticsearch.common.xcontent.ToXContentFragment, BaseAggregationBuilder, Rewriteable<AggregationBuilder>
A factory that knows how to create an 
Aggregator of a specific type.- 
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA rough count of the number of buckets thatAggregators built by this builder will contain per parent bucket used to validate sorts and pipeline aggregations.static classCommon xcontent fields shared among aggregator buildersNested classes/interfaces inherited from interface org.elasticsearch.common.xcontent.ToXContent
org.elasticsearch.common.xcontent.ToXContent.DelegatingMapParams, org.elasticsearch.common.xcontent.ToXContent.MapParams, org.elasticsearch.common.xcontent.ToXContent.ParamsNested classes/interfaces inherited from interface org.elasticsearch.common.io.stream.Writeable
Writeable.Reader<V>, Writeable.Writer<V> - 
Field Summary
FieldsModifier and TypeFieldDescriptionstatic longprotected AggregatorFactories.Builderprotected StringFields inherited from interface org.elasticsearch.index.query.Rewriteable
MAX_REWRITE_ROUNDSFields inherited from interface org.elasticsearch.common.xcontent.ToXContent
EMPTY_PARAMS - 
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAggregationBuilder(String name)Constructs a new aggregation builder.protectedAggregationBuilder(AggregationBuilder clone, AggregatorFactories.Builder factoriesBuilder) - 
Method Summary
Modifier and TypeMethodDescriptionabstract AggregationBuilder.BucketCardinalityA rough count of the number of buckets thatAggregators built by this builder will contain per owning parent bucket.protected abstract AggregatorFactorybuild(AggregationContext context, AggregatorFactory parent)Internal: build anAggregatorFactorybased on the configuration of this builder.Build a tree ofPipelineAggregators to modify the tree of aggregation results after the final reduction.longBytes to preallocate on the "request" breaker for this aggregation.protected AggregationBuilderdoRewrite(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 aggregationsReturn the configured set of subaggregationsrewrite(QueryRewriteContext context)Rewrites this instance based on the provided context.abstract AggregationBuildersetMetadata(Map<String,Object> metadata)Associate metadata with thisAggregationBuilder.protected abstract AggregationBuildershallowCopy(AggregatorFactories.Builder factoriesBuilder, Map<String,Object> metadata)Create a shallow copy of this builder and replacingfactoriesBuilderandmetadata.abstract AggregationBuildersubAggregation(AggregationBuilder aggregation)Add a sub aggregation to this builder.abstract AggregationBuildersubAggregation(PipelineAggregationBuilder aggregation)Add a sub aggregation to this builder.abstract AggregationBuildersubAggregations(AggregatorFactories.Builder subFactories)Internal: Registers sub-factories with this factory.toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.elasticsearch.search.aggregations.BaseAggregationBuilder
getTypeMethods inherited from interface org.elasticsearch.common.io.stream.NamedWriteable
getWriteableNameMethods inherited from interface org.elasticsearch.common.xcontent.ToXContent
toXContentMethods inherited from interface org.elasticsearch.common.xcontent.ToXContentFragment
isFragment 
- 
Field Details
- 
DEFAULT_PREALLOCATION
public static final long DEFAULT_PREALLOCATION- See Also:
 - Constant Field Values
 
 - 
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 IOExceptionInternal: build anAggregatorFactorybased on the configuration of this builder.- Throws:
 IOException
 - 
setMetadata
Associate metadata with thisAggregationBuilder.- Specified by:
 setMetadatain 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 - 
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:
 subAggregationsin 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 replacingfactoriesBuilderandmetadata. Used byrewrite(QueryRewriteContext). - 
rewrite
Description copied from interface:RewriteableRewrites 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:
 rewritein 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 ofPipelineAggregators to modify the tree of aggregation results after the final reduction. - 
bucketCardinality
A rough count of the number of buckets thatAggregators 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. - 
toString
 
 -