# Use one aggregation to calculate another and return only the required aggregation

**URL:** <https://discuss.elastic.co/t/use-one-aggregation-to-calculate-another-and-return-only-the-required-aggregation/134171>\
**Category:** Elasticsearch\
**Created:** [June 1, 2018, 8:32am UTC](https://discuss.elastic.co/t/use-one-aggregation-to-calculate-another-and-return-only-the-required-aggregation/134171 "2018-06-01T08:32:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![siddharth\_jain](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@siddharth\_jain](https://discuss.elastic.co/u/siddharth_jain)\
**Post date:** [June 1, 2018, 8:32am UTC](https://discuss.elastic.co/t/use-one-aggregation-to-calculate-another-and-return-only-the-required-aggregation/134171/1 "2018-06-01T08:32:12Z")

</div>

I am using a sum aggregation to find the minimum of all the sums.

```
GET /prod*/_search
{
  "size": 0, 
  "aggs": {
    "buckets": {
      "terms": {
        "field": "city.keyword",
        "size": 10
      },
      "aggs": {
        "city_views": {
          "sum": {
            "field": "View"
          }
        }
      }
    },
    "min_city_view": {
      "min_bucket": {
        "buckets_path": "buckets>city_views"
      }
    }
  }
}

```

I only want it to return the minimum value, not the sum aggregations(so that I can reduce the data transfer from server), how is it possible?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 1, 2018, 8:45am UTC](https://discuss.elastic.co/t/use-one-aggregation-to-calculate-another-and-return-only-the-required-aggregation/134171/2 "2018-06-01T08:45:49Z")

</div>

May be this could help: [https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline.html)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 29, 2018, 8:45am UTC](https://discuss.elastic.co/t/use-one-aggregation-to-calculate-another-and-return-only-the-required-aggregation/134171/3 "2018-06-29T08:45:59Z")

</div>

Closed on June 29, 2018, 8:45am UTC

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
