[[java-rest-high-aggregation-builders]]
=== Building Aggregations

This page lists all the available aggregations with their corresponding `AggregationBuilder` class name and helper method name in the
`AggregationBuilders` or `PipelineAggregatorBuilders` utility classes.

:agg-ref:        {elasticsearch-javadoc}/org/elasticsearch/search/aggregations
:parentjoin-ref: {parent-join-client-javadoc}/org/elasticsearch/join/aggregations
:matrixstats-ref: {matrixstats-client-javadoc}/org/elasticsearch/search/aggregations

==== Metrics Aggregations
[options="header"]
|======
| Aggregation                                                                                        | AggregationBuilder Class                                                                                | Method in AggregationBuilders
| {ref}/search-aggregations-metrics-avg-aggregation.html[Avg]                                        | {agg-ref}/metrics/avg/AvgAggregationBuilder.html[AvgAggregationBuilder]                                 | {agg-ref}/AggregationBuilders.html#avg-java.lang.String-[AggregationBuilders.avg()]
| {ref}/search-aggregations-metrics-cardinality-aggregation.html[Cardinality]                        | {agg-ref}/metrics/cardinality/CardinalityAggregationBuilder.html[CardinalityAggregationBuilder]         | {agg-ref}/AggregationBuilders.html#cardinality-java.lang.String-[AggregationBuilders.cardinality()]
| {ref}/search-aggregations-metrics-extendedstats-aggregation.html[Extended Stats]                   | {agg-ref}/metrics/stats/extended/ExtendedStatsAggregationBuilder.html[ExtendedStatsAggregationBuilder]  | {agg-ref}/AggregationBuilders.html#extendedStats-java.lang.String-[AggregationBuilders.extendedStats()]
| {ref}/search-aggregations-metrics-geobounds-aggregation.html[Geo Bounds]                           | {agg-ref}/metrics/geobounds/GeoBoundsAggregationBuilder.html[GeoBoundsAggregationBuilder]               | {agg-ref}/AggregationBuilders.html#geoBounds-java.lang.String-[AggregationBuilders.geoBounds()]
| {ref}/search-aggregations-metrics-geocentroid-aggregation.html[Geo Centroid]                       | {agg-ref}/metrics/geocentroid/GeoCentroidAggregationBuilder.html[GeoCentroidAggregationBuilder]         | {agg-ref}/AggregationBuilders.html#geoCentroid-java.lang.String-[AggregationBuilders.geoCentroid()]
| {ref}/search-aggregations-metrics-max-aggregation.html[Max]                                        | {agg-ref}/metrics/max/MaxAggregationBuilder.html[MaxAggregationBuilder]                                 | {agg-ref}/AggregationBuilders.html#max-java.lang.String-[AggregationBuilders.max()]
| {ref}/search-aggregations-metrics-min-aggregation.html[Min]                                        | {agg-ref}/metrics/min/MinAggregationBuilder.html[MinxAggregationBuilder]                                | {agg-ref}/AggregationBuilders.html#min-java.lang.String-[AggregationBuilders.min()]
| {ref}/search-aggregations-metrics-percentile-aggregation.html[Percentiles]                         | {agg-ref}/metrics/percentiles/PercentilesAggregationBuilder.html[PercentilesAggregationBuilder]         | {agg-ref}/AggregationBuilders.html#percentiles-java.lang.String-[AggregationBuilders.percentiles()]
| {ref}/search-aggregations-metrics-percentile-rank-aggregation.html[Percentile Ranks]               | {agg-ref}/metrics/percentiles/PercentileRanksAggregationBuilder.html[PercentileRanksAggregationBuilder] | {agg-ref}/AggregationBuilders.html#percentileRanks-java.lang.String-[AggregationBuilders.percentileRanks()]
| {ref}/search-aggregations-metrics-scripted-metric-aggregation.html[Scripted Metric]                | {agg-ref}/metrics/scripted/ScriptedMetricAggregationBuilder.html[ScriptedMetricAggregationBuilder]      | {agg-ref}/AggregationBuilders.html#scriptedMetric-java.lang.String-[AggregationBuilders.scriptedMetric()]
| {ref}/search-aggregations-metrics-stats-aggregation.html[Stats]                                    | {agg-ref}/metrics/stats/StatsAggregationBuilder.html[StatsAggregationBuilder]                           | {agg-ref}/AggregationBuilders.html#stats-java.lang.String-[AggregationBuilders.stats()]
| {ref}/search-aggregations-metrics-sum-aggregation.html[Sum]                                        | {agg-ref}/metrics/sum/SumAggregationBuilder.html[SumAggregationBuilder]                                 | {agg-ref}/AggregationBuilders.html#sum-java.lang.String-[AggregationBuilders.sum()]
| {ref}/search-aggregations-metrics-top-hits-aggregation.html[Top hits]                              | {agg-ref}/metrics/tophits/TopHitsAggregationBuilder.html[TopHitsAggregationBuilder]                     | {agg-ref}/AggregationBuilders.html#topHits-java.lang.String-[AggregationBuilders.topHits()]
| {ref}/search-aggregations-metrics-valuecount-aggregation.html[Value Count]                         | {agg-ref}/metrics/valuecount/ValueCountAggregationBuilder.html[ValueCountAggregationBuilder]            | {agg-ref}/AggregationBuilders.html#count-java.lang.String-[AggregationBuilders.count()]
|======

==== Bucket Aggregations
[options="header"]
|======
| Aggregation                                                                                        | AggregationBuilder Class                                                                                 | Method in AggregationBuilders
| {ref}/search-aggregations-bucket-adjacency-matrix-aggregation.html[Adjacency Matrix]               | {agg-ref}/bucket/adjacency/AdjacencyMatrixAggregationBuilder.html[AdjacencyMatrixAggregationBuilder]     | {agg-ref}/AggregationBuilders.html#adjacencyMatrix-java.lang.String-java.util.Map-[AggregationBuilders.adjacencyMatrix()]
| {ref}/search-aggregations-bucket-children-aggregation.html[Children]                               | {parentjoin-ref}/ChildrenAggregationBuilder.html[ChildrenAggregationBuilder]                             |
| {ref}/search-aggregations-bucket-datehistogram-aggregation.html[Date Histogram]                    | {agg-ref}/bucket/histogram/DateHistogramAggregationBuilder.html[DateHistogramAggregationBuilder]         | {agg-ref}/AggregationBuilders.html#dateHistogram-java.lang.String-[AggregationBuilders.dateHistogram()]
| {ref}/search-aggregations-bucket-daterange-aggregation.html[Date Range]                            | {agg-ref}/bucket/range/DateRangeAggregationBuilder.html[DateRangeAggregationBuilder]                     | {agg-ref}/AggregationBuilders.html#dateRange-java.lang.String-[AggregationBuilders.dateRange()]
| {ref}/search-aggregations-bucket-diversified-sampler-aggregation.html[Diversified Sampler]         | {agg-ref}/bucket/sampler/DiversifiedAggregationBuilder.html[DiversifiedAggregationBuilder]               | {agg-ref}/AggregationBuilders.html#diversifiedSampler-java.lang.String-[AggregationBuilders.diversifiedSampler()]
| {ref}/search-aggregations-bucket-filter-aggregation.html[Filter]                                   | {agg-ref}/bucket/filter/FilterAggregationBuilder.html[FilterAggregationBuilder]                          | {agg-ref}/AggregationBuilders.html#filter-java.lang.String-org.elasticsearch.index.query.QueryBuilder-[AggregationBuilders.filter()]
| {ref}/search-aggregations-bucket-filters-aggregation.html[Filters]                                 | {agg-ref}/bucket/filters/FiltersAggregationBuilder.html[FiltersAggregationBuilder]                        | {agg-ref}/AggregationBuilders.html#filters-java.lang.String-org.elasticsearch.index.query.QueryBuilder...-[AggregationBuilders.filters()]
| {ref}/search-aggregations-bucket-geodistance-aggregation.html[Geo Distance]                        | {agg-ref}/bucket/range/GeoDistanceAggregationBuilder.html[GeoDistanceAggregationBuilder]                 | {agg-ref}/AggregationBuilders.html#geoDistance-java.lang.String-org.elasticsearch.common.geo.GeoPoint-[AggregationBuilders.geoDistance()]
| {ref}/search-aggregations-bucket-geohashgrid-aggregation.html[GeoHash Grid]                        | {agg-ref}/bucket/geogrid/GeoGridAggregationBuilder.html[GeoGridAggregationBuilder]                       | {agg-ref}/AggregationBuilders.html#geohashGrid-java.lang.String-[AggregationBuilders.geohashGrid()]
| {ref}/search-aggregations-bucket-global-aggregation.html[Global]                                   | {agg-ref}/bucket/global/GlobalAggregationBuilder.html[GlobalAggregationBuilder]                          | {agg-ref}/AggregationBuilders.html#global-java.lang.String-[AggregationBuilders.global()]
| {ref}/search-aggregations-bucket-histogram-aggregation.html[Histogram]                             | {agg-ref}/bucket/histogram/HistogramAggregationBuilder.html[HistogramAggregationBuilder]                 | {agg-ref}/AggregationBuilders.html#histogram-java.lang.String-[AggregationBuilders.histogram()]
| {ref}/search-aggregations-bucket-iprange-aggregation.html[IP Range]                                | {agg-ref}/bucket/range/IpRangeAggregationBuilder.html[IpRangeAggregationBuilder]                         | {agg-ref}/AggregationBuilders.html#ipRange-java.lang.String-[AggregationBuilders.ipRange()]
| {ref}/search-aggregations-bucket-missing-aggregation.html[Missing]                                 | {agg-ref}/bucket/missing/MissingAggregationBuilder.html[MissingAggregationBuilder]                       | {agg-ref}/AggregationBuilders.html#missing-java.lang.String-[AggregationBuilders.missing()]
| {ref}/search-aggregations-bucket-nested-aggregation.html[Nested]                                   | {agg-ref}/bucket/nested/NestedAggregationBuilder.html[NestedAggregationBuilder]                          | {agg-ref}/AggregationBuilders.html#nested-java.lang.String-java.lang.String-[AggregationBuilders.nested()]
| {ref}/search-aggregations-bucket-range-aggregation.html[Range]                                     | {agg-ref}/bucket/range/RangeAggregationBuilder.html[RangeAggregationBuilder]                             | {agg-ref}/AggregationBuilders.html#range-java.lang.String-[AggregationBuilders.range()]
| {ref}/search-aggregations-bucket-reverse-nested-aggregation.html[Reverse nested]                   | {agg-ref}/bucket/nested/ReverseNestedAggregationBuilder.html[ReverseNestedAggregationBuilder]            | {agg-ref}/AggregationBuilders.html#reverseNested-java.lang.String-[AggregationBuilders.reverseNested()]
| {ref}/search-aggregations-bucket-sampler-aggregation.html[Sampler]                                 | {agg-ref}/bucket/sampler/SamplerAggregationBuilder.html[SamplerAggregationBuilder]                       | {agg-ref}/AggregationBuilders.html#sampler-java.lang.String-[AggregationBuilders.sampler()]
| {ref}/search-aggregations-bucket-significantterms-aggregation.html[Significant Terms]              | {agg-ref}/bucket/significant/SignificantTermsAggregationBuilder.html[SignificantTermsAggregationBuilder] | {agg-ref}/AggregationBuilders.html#significantTerms-java.lang.String-[AggregationBuilders.significantTerms()]
| {ref}/search-aggregations-bucket-significanttext-aggregation.html[Significant Text]                | {agg-ref}/bucket/significant/SignificantTextAggregationBuilder.html[SignificantTextAggregationBuilder]   | {agg-ref}/AggregationBuilders.html#significantText-java.lang.String-java.lang.String-[AggregationBuilders.significantText()]
| {ref}/search-aggregations-bucket-terms-aggregation.html[Terms]                                     | {agg-ref}/bucket/terms/TermsAggregationBuilder.html[TermsAggregationBuilder]                             | {agg-ref}/AggregationBuilders.html#terms-java.lang.String-[AggregationBuilders.terms()]
|======

==== Pipeline Aggregations
[options="header"]
|======
| Pipeline on                                                                                        | PipelineAggregationBuilder Class                                                                                                                  | Method in PipelineAggregatorBuilders
| {ref}/search-aggregations-pipeline-avg-bucket-aggregation.html[Avg Bucket]                         | {agg-ref}/pipeline/bucketmetrics/avg/AvgBucketPipelineAggregationBuilder.html[AvgBucketPipelineAggregationBuilder]                                | {agg-ref}/pipeline/PipelineAggregatorBuilders.html#avgBucket-java.lang.String-java.lang.String-[PipelineAggregatorBuilders.avgBucket()]
| {ref}/search-aggregations-pipeline-derivative-aggregation.html[Derivative]                         | {agg-ref}/pipeline/derivative/DerivativePipelineAggregationBuilder.html[DerivativePipelineAggregationBuilder]                                     | {agg-ref}/pipeline/PipelineAggregatorBuilders.html#derivative-java.lang.String-java.lang.String-[PipelineAggregatorBuilders.derivative()]
| {ref}/search-aggregations-pipeline-max-bucket-aggregation.html[Max Bucket]                         | {agg-ref}/pipeline/bucketmetrics/max/MaxBucketPipelineAggregationBuilder.html[MaxBucketPipelineAggregationBuilder]                                | {agg-ref}/pipeline/PipelineAggregatorBuilders.html#maxBucket-java.lang.String-java.lang.String-[PipelineAggregatorBuilders.maxBucket()]
| {ref}/search-aggregations-pipeline-min-bucket-aggregation.html[Min Bucket]                         | {agg-ref}/pipeline/bucketmetrics/min/MinBucketPipelineAggregationBuilder.html[MinBucketPipelineAggregationBuilder]                                | {agg-ref}/pipeline/PipelineAggregatorBuilders.html#minBucket-java.lang.String-java.lang.String-[PipelineAggregatorBuilders.minBucket()]
| {ref}/search-aggregations-pipeline-sum-bucket-aggregation.html[Sum Bucket]                         | {agg-ref}/pipeline/bucketmetrics/sum/SumBucketPipelineAggregationBuilder.html[SumBucketPipelineAggregationBuilder]                                | {agg-ref}/pipeline/PipelineAggregatorBuilders.html#sumBucket-java.lang.String-java.lang.String-[PipelineAggregatorBuilders.sumBucket()]
| {ref}/search-aggregations-pipeline-stats-bucket-aggregation.html[Stats Bucket]                     | {agg-ref}/pipeline/bucketmetrics/stats/StatsBucketPipelineAggregationBuilder.html[StatsBucketPipelineAggregationBuilder]                          | {agg-ref}/pipeline/PipelineAggregatorBuilders.html#statsBucket-java.lang.String-java.lang.String-[PipelineAggregatorBuilders.statsBucket()]
| {ref}/search-aggregations-pipeline-extended-stats-bucket-aggregation.html[Extended Stats Bucket]   | {agg-ref}/pipeline/bucketmetrics/stats/extended/ExtendedStatsBucketPipelineAggregationBuilder.html[ExtendedStatsBucketPipelineAggregationBuilder] | {agg-ref}/pipeline/PipelineAggregatorBuilders.html#extendedStatsBucket-java.lang.String-java.lang.String-[PipelineAggregatorBuilders.extendedStatsBucket()]
| {ref}/search-aggregations-pipeline-percentiles-bucket-aggregation.html[Percentiles Bucket]         | {agg-ref}/pipeline/bucketmetrics/percentile/PercentilesBucketPipelineAggregationBuilder.html[PercentilesBucketPipelineAggregationBuilder]         | {agg-ref}/pipeline/PipelineAggregatorBuilders.html#percentilesBucket-java.lang.String-java.lang.String-[PipelineAggregatorBuilders.percentilesBucket()]
| {ref}/search-aggregations-pipeline-movavg-aggregation.html[Moving Average]                         | {agg-ref}/pipeline/movavg/MovAvgPipelineAggregationBuilder.html[MovAvgPipelineAggregationBuilder]                                                 | {agg-ref}/pipeline/PipelineAggregatorBuilders.html#movingAvg-java.lang.String-java.lang.String-[PipelineAggregatorBuilders.movingAvg()]
| {ref}/search-aggregations-pipeline-cumulative-sum-aggregation.html[Cumulative Sum]                 | {agg-ref}/pipeline/cumulativesum/CumulativeSumPipelineAggregationBuilder.html[CumulativeSumPipelineAggregationBuilder]                            | {agg-ref}/pipeline/PipelineAggregatorBuilders.html#cumulativeSum-java.lang.String-java.lang.String-[PipelineAggregatorBuilders.cumulativeSum()]
| {ref}/search-aggregations-pipeline-bucket-script-aggregation.html[Bucket Script]                   | {agg-ref}/pipeline/bucketscript/BucketScriptPipelineAggregationBuilder.html[BucketScriptPipelineAggregationBuilder]                               | {agg-ref}/pipeline/PipelineAggregatorBuilders.html#bucketScript-java.lang.String-java.util.Map-org.elasticsearch.script.Script-[PipelineAggregatorBuilders.bucketScript()]
| {ref}/search-aggregations-pipeline-bucket-selector-aggregation.html[Bucket Selector]               | {agg-ref}/pipeline/bucketselector/BucketSelectorPipelineAggregationBuilder.html[BucketSelectorPipelineAggregationBuilder]                         | {agg-ref}/pipeline/PipelineAggregatorBuilders.html#bucketSelector-java.lang.String-java.util.Map-org.elasticsearch.script.Script-[PipelineAggregatorBuilders.bucketSelector()]
| {ref}/search-aggregations-pipeline-serialdiff-aggregation.html[Serial Differencing]                | {agg-ref}/pipeline/serialdiff/SerialDiffPipelineAggregationBuilder.html[SerialDiffPipelineAggregationBuilder]                                     | {agg-ref}/pipeline/PipelineAggregatorBuilders.html#diff-java.lang.String-java.lang.String-[PipelineAggregatorBuilders.diff()]
|======

==== Matrix Aggregations
[options="header"]
|======
| Aggregation                                                                                        | AggregationBuilder Class                                                                  | Method in MatrixStatsAggregationBuilders
| {ref}/search-aggregations-matrix-stats-aggregation.html[Matrix Stats]                              | {matrixstats-ref}/matrix/stats/MatrixStatsAggregationBuilder.html[MatrixStatsAggregationBuilder]  | {matrixstats-ref}/MatrixStatsAggregationBuilders.html#matrixStats-java.lang.String-[MatrixStatsAggregationBuilders.matrixStats()]
|======
