﻿---
title: Aggregations
description: This page covers how to run aggregations with the Go client using the typed API and the esdsl builders. For the full aggregations reference, see Aggregations...
url: https://www.elastic.co/elastic/docs-builder/docs/3174/reference/elasticsearch/clients/go/using-the-api/aggregations
products:
  - Elasticsearch
  - Elasticsearch Client
  - Elasticsearch Go Client
---

# Aggregations
This page covers how to run aggregations with the Go client using the [typed API](https://www.elastic.co/elastic/docs-builder/docs/3174/reference/elasticsearch/clients/go/typed-api) and the [`esdsl`](https://www.elastic.co/elastic/docs-builder/docs/3174/reference/elasticsearch/clients/go/typed-api/esdsl) builders. For the full aggregations reference, see [Aggregations](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3174/explore-analyze/query-filter/aggregations) in the Elasticsearch documentation. For raw-JSON aggregations, see the [low-level API](https://www.elastic.co/elastic/docs-builder/docs/3174/reference/elasticsearch/clients/go/low-level-api).
```go
import "github.com/elastic/go-elasticsearch/v9/typedapi/esdsl"
```

Given documents with a `price` field, we run a sum aggregation on `index_name`. The `esdsl` aggregation builders let you define aggregations with a fluent syntax:
```go
totalPricesAgg, err := es.Search().
    Index("index_name").
    Size(0).
    AddAggregation("total_prices",
        esdsl.NewSumAggregation().Field("price"),
    ).
    Do(context.Background())
```