# ExtendedStatsBuckets gives negative variance

**URL:** <https://discuss.elastic.co/t/extendedstatsbuckets-gives-negative-variance/141198>\
**Category:** Elasticsearch\
**Created:** [July 23, 2018, 2:48pm UTC](https://discuss.elastic.co/t/extendedstatsbuckets-gives-negative-variance/141198 "2018-07-23T14:48:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![uyth](https://avatars.discourse-cdn.com/v4/letter/u/6a8cbe/32.png) [@uyth](https://discuss.elastic.co/u/uyth)\
**Post date:** [July 23, 2018, 2:48pm UTC](https://discuss.elastic.co/t/extendedstatsbuckets-gives-negative-variance/141198/1 "2018-07-23T14:48:07Z")

</div>

Elasticsearch v. 6.2.4

ExtendedStats over a negative field in a DateHistogram gives a negative variance, and NaN for standard deviation. I believe this is a bug since variance should never be negative as it is derived from a squared value.

This is what the response looks like:

```
{  
    "name":"burndown_stats",
    "count":39,
    "min":-9.4948557E7,
    "max":-9.4948557E7,
    "sum":-3.702993723E9,
    "avg":-9.4948557E7,
    "sumOfSquares":3.5159391057890765E17,
    "variance":-1.641025641025641,
    "stdDeviation":"NaN",
    "type":"extended_stats_bucket",
    "stdDeviationAsString":"NaN",
    "sumOfSquaresAsString":"3.5159391057890765E17",
    "varianceAsString":"-1.641025641025641",
    "minAsString":"-9.4948557E7",
    "maxAsString":"-9.4948557E7",
    "avgAsString":"-9.4948557E7",
    "sumAsString":"-3.702993723E9",
    "metaData":null,
    "fragment":true
}
```

---

<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:** [August 20, 2018, 2:48pm UTC](https://discuss.elastic.co/t/extendedstatsbuckets-gives-negative-variance/141198/2 "2018-08-20T14:48:17Z")

</div>

Closed on August 20, 2018, 2:48pm UTC

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