# BUG - Sum bucket aggregation always returning zero

**URL:** <https://discuss.elastic.co/t/bug-sum-bucket-aggregation-always-returning-zero/218152>\
**Category:** Elasticsearch\
**Created:** [February 6, 2020, 10:56am UTC](https://discuss.elastic.co/t/bug-sum-bucket-aggregation-always-returning-zero/218152 "2020-02-06T10:56:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![wiouser](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wiouser/32/45741_2.png) [@wiouser](https://discuss.elastic.co/u/wiouser)\
**Post date:** [February 6, 2020, 10:56am UTC](https://discuss.elastic.co/t/bug-sum-bucket-aggregation-always-returning-zero/218152/1 "2020-02-06T10:56:47Z")

</div>

Hi,

I am trying to do a sum bucket using pipeline aggregation path separator.  
But sum bucket value is always zero. It doesn't even throw an error.  
I don't have any zero values in my data.

```
{
  "size": 0,
  "aggs": {
"devicelist": {
  "terms": {
    "field": "device",
    "size": 9999},
    "aggs": {
      "currentstatus": {
        "terms": {
          "field": "status.keyword",
          "size": 1,
          "order": {
            "latest": "desc"
          }},
          "aggs": {
            "latest": {
              "max": {
                "field": "time"
              }
            },
            "total": {
              "sum": {
                "field": "statusInt"
              }
            }
      }
    }
  }
},
"sumd": {
  "sum_bucket": {
    "buckets_path": "devicelist>currentstatus['SUCCESS']>total"
  }
}
  }
}
```

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [February 7, 2020, 2:59pm UTC](https://discuss.elastic.co/t/bug-sum-bucket-aggregation-always-returning-zero/218152/2 "2020-02-07T14:59:39Z")

</div>

can you provide a fully reproducible example including index creation, document indexing and the whole query and the exact elasticsearch version you are using? otherwise this will be hard to reproduce.

Thanks!

---

<div class="post-metadata">

**Author:** ![wiouser](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wiouser/32/45741_2.png) [@wiouser](https://discuss.elastic.co/u/wiouser)\
**Post date:** [February 10, 2020, 1:04pm UTC](https://discuss.elastic.co/t/bug-sum-bucket-aggregation-always-returning-zero/218152/3 "2020-02-10T13:04:34Z")

</div>

Hi @spinscale ,

Thanks for the reply.  
I am using AWS Elasticsearch ver 6.7

Documents are written to index when there is status change from various devices along with time. Mappings and index creation handled by elasticsearch defaults.  
The query I have posted in the question is the exact query.

Sample documents

{"time": 03:00, "device": "device3", "status": "SUCCESS", "statusInt": 1}  
{"time": 03:00, "device": "device2", "status": "SUCCESS", "statusInt": 1}  
{"time": 02:05, "device": "device2", "status": "FAILURE", "statusInt": 0}  
{"time": 02:00, "device": "device2", "status": "FAILURE", "statusInt": 0}  
{"time": 01:05, "device": "device1", "status": "FAILURE", "statusInt": 0}  
{"time": 01:00, "device": "device1", "status": "SUCCESS", "statusInt": 1}

I expect the query to provide the sum\_bucket aggreagation value as 2, summing up `total` aggregation field under the terms device2-\>SUCCESS and device3-\>SUCCESS

Use case: In a time series data, logging status from multiple devices, I want to get the latest status per device and count up the number of success devices. Exporting the latest status of all the devices and doing it on the client side is not an option.  
That is why I decided to use sum\_bucket and buckets\_path syntax to select only SUCCESS results.

---

<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:** [March 9, 2020, 1:04pm UTC](https://discuss.elastic.co/t/bug-sum-bucket-aggregation-always-returning-zero/218152/4 "2020-03-09T13:04:35Z")

</div>

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