# Range query on the result of Sum aggregation

**URL:** <https://discuss.elastic.co/t/range-query-on-the-result-of-sum-aggregation/153731>\
**Category:** Elasticsearch\
**Created:** [October 24, 2018, 6:53am UTC](https://discuss.elastic.co/t/range-query-on-the-result-of-sum-aggregation/153731 "2018-10-24T06:53:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nikhil\_Nambiar](https://avatars.discourse-cdn.com/v4/letter/n/9fc29f/32.png) [@Nikhil\_Nambiar](https://discuss.elastic.co/u/Nikhil_Nambiar)\
**Post date:** [October 24, 2018, 6:53am UTC](https://discuss.elastic.co/t/range-query-on-the-result-of-sum-aggregation/153731/1 "2018-10-24T06:53:31Z")

</div>

I am trying to apply range on the result that I got from sum aggregation.  
Below query helps me to find sum of amount of individual phone

```
{
  "size": 0,
  "aggs": {
    "group_by_phone": {
      "terms": {
        "field": "phone.keyword"
      },
      "aggs": {
        "total_call_amount": {
          "sum": {
            "field": "amount"
          }
        }
      }
    }
  }
}

```

Now I want to filter by applying range on total\_call\_amount which is summing above 8000.

---

<div class="post-metadata">

**Author:** ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)\
**Post date:** [October 29, 2018, 11:48am UTC](https://discuss.elastic.co/t/range-query-on-the-result-of-sum-aggregation/153731/2 "2018-10-29T11:48:51Z")

</div>

The [bucket\_selector](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-bucket-selector-aggregation.html) aggregation should work in this case. You can use it to filter out all buckets that have a `total_call_amount < 8000`

---

<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:** [November 26, 2018, 11:48am UTC](https://discuss.elastic.co/t/range-query-on-the-result-of-sum-aggregation/153731/3 "2018-11-26T11:48:54Z")

</div>

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