Closed
Description
Elasticsearch version: 7.0.0-alpha1-SNAPSHOT, Build: 9e36764/2017-10-03T12:16:42.018Z
Plugins installed: [x-pack]
JVM version: 1.8.0_144
OS version: macOS 10.13
Description of the problem including expected versus actual behavior:
You get different results for e.g. a distinct sum
aggregation vs. the sum
within the stats
aggregation. For a doc_count
of 0
, the sum
aggregation returns 0
whereas the sum
within the stats
aggregation is null
.
Steps to reproduce:
- Create some documents:
PUT my_test/test/1
{
"category" : "c1",
"value": 1
}
PUT my_test/test/2
{
"category" : "c2"
}
PUT my_test/test/3
{
"category" : "c3",
"value": 1
}
PUT my_test/test/4
{
"category" : "c3",
"value": 1
}
- Run a nested aggregation:
POST my_test/_search
{
"size": 0,
"aggregations": {
"categories": {
"terms": {
"field": "category.keyword"
},
"aggs": {
"my_min": {
"min": {
"field": "value"
}
},
"my_max": {
"max": {
"field": "value"
}
},
"my_avg": {
"avg": {
"field": "value"
}
},
"my_sum": {
"sum": {
"field": "value"
}
},
"my_stats": {
"stats": {
"field": "value"
}
}
}
}
}
}
- The result looks like this:
"aggregations": {
"categories": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "c3",
"doc_count": 2,
"my_stats": {
"count": 2,
"min": 1,
"max": 1,
"avg": 1,
"sum": 2
},
"my_max": {
"value": 1
},
"my_avg": {
"value": 1
},
"my_min": {
"value": 1
},
"my_sum": {
"value": 2
}
},
{
"key": "c1",
"doc_count": 1,
"my_stats": {
"count": 1,
"min": 1,
"max": 1,
"avg": 1,
"sum": 1
},
"my_max": {
"value": 1
},
"my_avg": {
"value": 1
},
"my_min": {
"value": 1
},
"my_sum": {
"value": 1
}
},
{
"key": "c2",
"doc_count": 1,
"my_stats": {
"count": 0,
"min": null,
"max": null,
"avg": null,
"sum": null
},
"my_max": {
"value": null
},
"my_avg": {
"value": null
},
"my_min": {
"value": null
},
"my_sum": {
"value": 0
}
}
]
}
}
The document in category c2
doesn't include the value
field. All the aggregation results have a value of null
whereas only the sum
aggregation has a value
of 0
.