Class AggregationBuilder

java.lang.Object
org.elasticsearch.search.aggregations.AggregationBuilder
All Implemented Interfaces:
NamedWriteable, Writeable, Rewriteable<AggregationBuilder>, BaseAggregationBuilder, ToXContent, ToXContentFragment
Direct Known Subclasses:
AbstractAggregationBuilder

public abstract class AggregationBuilder extends Object implements NamedWriteable, ToXContentFragment, BaseAggregationBuilder, Rewriteable<AggregationBuilder>
A factory that knows how to create an Aggregator of a specific type.
  • Field Details

  • Constructor Details

    • AggregationBuilder

      protected AggregationBuilder(String name)
      Constructs a new aggregation builder.
      Parameters:
      name - The aggregation name
    • AggregationBuilder

      protected AggregationBuilder(AggregationBuilder clone, AggregatorFactories.Builder factoriesBuilder)
  • Method Details

    • getName

      public String getName()
      Return this aggregation's name.
    • getOutputFieldNames

      public Optional<Set<String>> 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 an AggregatorFactory based on the configuration of this builder.
      Throws:
      IOException
    • setMetadata

      public abstract AggregationBuilder setMetadata(Map<String,Object> metadata)
      Associate metadata with this AggregationBuilder.
      Specified by:
      setMetadata in interface BaseAggregationBuilder
    • getMetadata

      public abstract Map<String,Object> getMetadata()
      Return any associated metadata with this AggregationBuilder.
    • subAggregation

      public abstract AggregationBuilder subAggregation(AggregationBuilder aggregation)
      Add a sub aggregation to this builder.
    • subAggregation

      public abstract AggregationBuilder subAggregation(PipelineAggregationBuilder aggregation)
      Add a sub aggregation to this builder.
    • getSubAggregations

      public Collection<AggregationBuilder> getSubAggregations()
      Return the configured set of subaggregations
    • getPipelineAggregations

      public Collection<PipelineAggregationBuilder> getPipelineAggregations()
      Return the configured set of pipeline aggregations
    • subAggregations

      public abstract AggregationBuilder subAggregations(AggregatorFactories.Builder subFactories)
      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 by AggregatorFactories.parseAggregators(XContentParser).
      Specified by:
      subAggregations in interface BaseAggregationBuilder
      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 replacing factoriesBuilder and metadata. Used by rewrite(QueryRewriteContext).
    • rewrite

      public final AggregationBuilder rewrite(QueryRewriteContext context) throws IOException
      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 interface Rewriteable<AggregationBuilder>
      Throws:
      IOException
    • doRewrite

      protected AggregationBuilder doRewrite(QueryRewriteContext queryRewriteContext) throws IOException
      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

      public PipelineAggregator.PipelineTree buildPipelineTree()
      Build a tree of PipelineAggregators to modify the tree of aggregation results after the final reduction.
    • bucketCardinality

      public abstract AggregationBuilder.BucketCardinality bucketCardinality()
      A rough count of the number of buckets that Aggregators 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

      public String toString()
      Overrides:
      toString in class Object
    • isInSortOrderExecutionRequired

      public boolean isInSortOrderExecutionRequired()
      Return true if any of the child aggregations is a time-series aggregation that requires an in-order execution
    • 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 validated
      name - the name of the aggregation being validated
      addValidationError - 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 validated
      name - the name of the aggregation being validated
      addValidationError - callback to add validation errors