# Getting wrong results with sum metric

**URL:** <https://discuss.elastic.co/t/getting-wrong-results-with-sum-metric/52059>\
**Category:** Elasticsearch\
**Created:** [June 7, 2016, 11:31am UTC](https://discuss.elastic.co/t/getting-wrong-results-with-sum-metric/52059 "2016-06-07T11:31:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aviv.ratzon](https://avatars.discourse-cdn.com/v4/letter/a/ed655f/32.png) [@aviv.ratzon](https://discuss.elastic.co/u/aviv.ratzon)\
**Post date:** [June 7, 2016, 11:31am UTC](https://discuss.elastic.co/t/getting-wrong-results-with-sum-metric/52059/1 "2016-06-07T11:31:00Z")

</div>

Hi,  
I'm using Elasticsearch 2.3 and am having a strange problem. I'm loading data about defects with logstash to elasticsearch and when I sum the data I get wrong results.  
This is my query:  
\> {  
\> "aggs": {  
\> "2": {  
\> "terms": {  
\> "field": "Bug\_ID.raw",  
\> "size": 50,  
\> "order": {  
\> "1": "asc"  
\> }  
\> },  
\> "aggs": {  
\> "1": {  
\> "sum": {  
\> "field": "Fixed\_Count"  
\> }  
\> ....

result:  
\> "1": {  
\> "value": -2  
\> },  
\> "key": "20456",  
\> "doc\_count": 2  
\> },  
\> {  
\> "1": {  
\> "value": -2  
\> },  
\> "key": "21032",  
\> "doc\_count": 7  
\> },  
\> {  
\> "1": {  
\> "value": -2  
\> },  
\> "key": "21813",  
\> "doc\_count": 2  
\> .......

But when I filter for a specific bug ID:  
\> {  
\> "query": {  
\> "bool" : {  
\> "must" : [  
\> { "match" : { "Bug\_ID.raw": "20456" } }  
\> ]  
\> }  
\> },  
\> "aggs": {  
\> "2": {  
\> "terms": {  
\> "field": "Bug\_ID.raw",  
\> "size": 50,  
\> "order": {  
\> "1": "asc"  
\> }  
\> },  
\> "aggs": {  
\> "1": {  
\> "sum": {  
\> "field": "Fixed\_Count"  
\> }  
\> .......

result:  
\> "1": {  
\> "value": 0  
\> },  
\> "key": "20456",  
\> "doc\_count": 7

The correct answer is given only when I filter for a specific ID. I've found some posts with a similiar issue but they don't seem related to this.

In my logstash configuration I am using an aggregate filter.

thanks,  
aviv

---

<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:** [July 5, 2017, 10:45pm UTC](https://discuss.elastic.co/t/getting-wrong-results-with-sum-metric/52059/2 "2017-07-05T22:45:37Z")

</div>


