# Aggregation returns buckets with values even when hits count is zero? Bug?

**URL:** https://discuss.elastic.co/t/aggregation-returns-buckets-with-values-even-when-hits-count-is-zero-bug/33812
**Category:** Elasticsearch
**Created:** [November 4, 2015, 8:44pm UTC](https://discuss.elastic.co/t/aggregation-returns-buckets-with-values-even-when-hits-count-is-zero-bug/33812 "2015-11-04T20:44:40Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Manuel\_Islas](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/manuel_islas/32/5177_2.png) [@Manuel\_Islas](https://discuss.elastic.co/u/Manuel_Islas)
#### Post date: [November 4, 2015, 8:44pm UTC](https://discuss.elastic.co/t/aggregation-returns-buckets-with-values-even-when-hits-count-is-zero-bug/33812/1 "2015-11-04T20:44:40Z")

</div>

I have a range aggregation over a query, **the query returns zero hits** , but the aggregation returns some of the buckets with values, looks to me like a Bug, not sure if this is expected behavior, I think it should not and if it is it results highly confusing and woulod appreciate help on clarifying why the behavior.

The range aggregation as follows:

```
"aggs": {
"sender_agg": {
  "range": {
    "field": "ownerId",
    "ranges": [
      {
        "to": 140,
        "key": "others-1"
      },
      {
        "from": 140,
        "to": 141,
        "key": "140"
      },
      {
        "from": 141,
        "to": 145,
        "key": "others-2"
      },
      {
        "from": 145,
        "to": 146,
        "key": "145"
      },
      {
        "from": 146,
        "key": "others-3"
      }
    ]
  }
},
"score_agg": {
  "stats": {
    "script": "_score"
  }
}

```

}

and the response is:

```
{
"took": 16,
"timed_out": false,
"_shards": {
    "total": 1,
    "successful": 1,
    "failed": 0
},
**"hits": {**
    **"total": 0,**
    **"max_score": null,**
    **"hits": []**
 **},**"aggregations": {
    "sender_agg": {
        "buckets": [
            {
                **"key": "others-1",**
                **"to": 140,**
                **"to_as_string": "140.0",**
                **"doc_count": 1**
            },
            {
                **"key": "140",**
                **"from": 140,**
                **"from_as_string": "140.0",**
                **"to": 141,**
                **"to_as_string": "141.0",**
                **"doc_count": 1**
            },
            {
                **"key": "others-2",**
                **"from": 141,**
                **"from_as_string": "141.0",**
                **"to": 145,**
                **"to_as_string": "145.0",**
                **"doc_count": 2**
            },
            {
                "key": "145",
                "from": 145,
                "from_as_string": "145.0",
                "to": 146,
                "to_as_string": "146.0",
                "doc_count": 0
            },
            {
                "key": "others-3",
                "from": 146,
                "from_as_string": "146.0",
                "doc_count": 0
            }
        ]
    },
    "score_agg": {
        "count": 4,
        "min": 1,
        "max": 1,
        "avg": 1,
        "sum": 4
    }
}

```

}

---

<div class="post-metadata">

### Author: ![Manuel\_Islas](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/manuel_islas/32/5177_2.png) [@Manuel\_Islas](https://discuss.elastic.co/u/Manuel_Islas)
#### Post date: [November 9, 2015, 8:57pm UTC](https://discuss.elastic.co/t/aggregation-returns-buckets-with-values-even-when-hits-count-is-zero-bug/33812/2 "2015-11-09T20:57:59Z")

</div>

Anyone?

---

<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, 11:39pm UTC](https://discuss.elastic.co/t/aggregation-returns-buckets-with-values-even-when-hits-count-is-zero-bug/33812/3 "2017-07-05T23:39:39Z")

</div>


