# Stats aggregation returning inconsistent results

**URL:** https://discuss.elastic.co/t/stats-aggregation-returning-inconsistent-results/289377
**Category:** Elasticsearch
**Created:** [November 17, 2021, 12:48am UTC](https://discuss.elastic.co/t/stats-aggregation-returning-inconsistent-results/289377 "2021-11-17T00:48:58Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Doug\_Coburn](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/doug_coburn/32/81142_2.png) [@Doug\_Coburn](https://discuss.elastic.co/u/Doug_Coburn)
#### Post date: [November 17, 2021, 12:48am UTC](https://discuss.elastic.co/t/stats-aggregation-returning-inconsistent-results/289377/1 "2021-11-17T00:48:58Z")

</div>

Using version 7.9.2

```auto
curl -X POST 172.31.26.133:9200/5cab6838-5c3a-455d-9486-a708f6cb20a7/_search --data-raw '{"aggs":{"Stats":{"stats":{"field":"Date & Time"}}},"size":0}' -H 'content-type: application/json'

```

```auto
{
    "took": 0,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 0,
            "relation": "eq"
        },
        "max_score": null,
        "hits": []
    },
    "aggregations": {
        "Stats": {
            "count": 0,
            "min": null,
            "max": null,
            "avg": null,
            "sum": 0.0
        }
    }
}

```

```auto
curl -X POST 172.31.26.133:9200/5cab6838-5c3a-455d-9486-a708f6cb20a7/_search --data-raw '{"aggs":{"Stats":{"stats":{"field":"Date & Time"}}},"size":0}' -H 'content-type: application/json'

```

```auto
{
    "took": 0,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 162,
            "relation": "eq"
        },
        "max_score": null,
        "hits": []
    },
    "aggregations": {
        "Stats": {
            "count": 162,
            "min": 1199232000000.0,
            "max": 1204502400000.0,
            "avg": 1201575466666.6667,
            "sum": 194655225600000.0,
            "min_as_string": "2008-01-02T00:00:00.000",
            "max_as_string": "2008-03-03T00:00:00.000",
            "avg_as_string": "2008-01-29T02:57:46.666",
            "sum_as_string": "8138-05-19T00:00:00.000"
        }
    }
}

```

These are back to back identical calls returning two different results.

Date & Time is mapped as: "Date & Time":{"type":"date","format":"date\_hour\_minute\_second\_millis||epoch\_millis"}

I would expect this to return consistent results.

---

<div class="post-metadata">

### Author: ![Doug\_Coburn](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/doug_coburn/32/81142_2.png) [@Doug\_Coburn](https://discuss.elastic.co/u/Doug_Coburn)
#### Post date: [November 25, 2021, 7:27pm UTC](https://discuss.elastic.co/t/stats-aggregation-returning-inconsistent-results/289377/2 "2021-11-25T19:27:00Z")

</div>

This inconsistent behavior was caused by the index settings `refresh_interval` set to a value of `-1`.

We set the refresh\_interval to -1 when we populate a new index with a lot of records then we set it to `30s` afterwards. Apparently, this settings change didn't happen for this dataset.

---

<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: [December 23, 2021, 7:27pm UTC](https://discuss.elastic.co/t/stats-aggregation-returning-inconsistent-results/289377/3 "2021-12-23T19:27:12Z")

</div>

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