# Buckets empty in aggregates

**URL:** <https://discuss.elastic.co/t/buckets-empty-in-aggregates/37379>\
**Category:** Elasticsearch\
**Created:** [December 16, 2015, 4:39pm UTC](https://discuss.elastic.co/t/buckets-empty-in-aggregates/37379 "2015-12-16T16:39:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_D\_Ament](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/john_d_ament/32/764_2.png) [@John\_D\_Ament](https://discuss.elastic.co/u/John_D_Ament)\
**Post date:** [December 16, 2015, 4:39pm UTC](https://discuss.elastic.co/t/buckets-empty-in-aggregates/37379/1 "2015-12-16T16:39:14Z")

</div>

I'm using Elasticsearch 1.7.3. I have a very simple query, it's deployed as a template.

```
{
  "_source": false,
  "query": {
    "filtered": {
      "query": {
        "match_all": {}
      },
      "filter": {
        "range": {
          "record.openedDate": {
            "from": "{{from}}"
          }
        }
      }
    }
  },
  "aggs": {
    "openedMonth": {
      "date_histogram": {
        "field": "record.openedDate",
        "interval": "month"
      },
      "aggs": {
        "byType": {
          "terms": {
            "field": "_type"
          }
        }
      }
    }
  }
}

```

Usually the report returns buckets, every now and then the buckets come back as empty

```
{
  "openedMonth": {
    "buckets": [
      {
        "key": 1446336000000,
        "doc_count": 3,
        "byType": {
          "doc_count_error_upper_bound": 0,
          "sum_other_doc_count": 0,
          "buckets": []
        }
      },
      {
        "key": 1448928000000,
        "doc_count": 2,
        "byType": {
          "doc_count_error_upper_bound": 0,
          "sum_other_doc_count": 0,
          "buckets": []
        }
      }
    ]
  }
}

```

Any idea why the buckets are not coming back?

---

<div class="post-metadata">

**Author:** ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)\
**Post date:** [December 16, 2015, 4:46pm UTC](https://discuss.elastic.co/t/buckets-empty-in-aggregates/37379/2 "2015-12-16T16:46:24Z")

</div>

That does look a little strange given the date histogram shows 3 and 2 documents for the bucket. Could you add a `top_hits` aggregation alongside your `by_type` agg to see what the documents in each bucket look like?

Also, given the same value for `from` does the issue reproduce every time?

---

<div class="post-metadata">

**Author:** ![John\_D\_Ament](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/john_d_ament/32/764_2.png) [@John\_D\_Ament](https://discuss.elastic.co/u/John_D_Ament)\
**Post date:** [December 16, 2015, 5:13pm UTC](https://discuss.elastic.co/t/buckets-empty-in-aggregates/37379/3 "2015-12-16T17:13:25Z")

</div>

I added top hits, didn't impact. It shows the matching hits when its enabled. When buckets is empty, I still can see hits.

The value for from is static, not dynamic, in the test I'm running.

---

<div class="post-metadata">

**Author:** ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)\
**Post date:** [December 17, 2015, 9:37am UTC](https://discuss.elastic.co/t/buckets-empty-in-aggregates/37379/4 "2015-12-17T09:37:40Z")

</div>

I was asking for the top\_hits so we could see what they look like to debug what might be going on. Could you share the output from the request with top\_hits included?

---

<div class="post-metadata">

**Author:** ![John\_D\_Ament](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/john_d_ament/32/764_2.png) [@John\_D\_Ament](https://discuss.elastic.co/u/John_D_Ament)\
**Post date:** [December 17, 2015, 3:29pm UTC](https://discuss.elastic.co/t/buckets-empty-in-aggregates/37379/5 "2015-12-17T15:29:24Z")

</div>

Ah, sorry. Here's the full output.

```
{
  "openedMonth": {
    "buckets": [
      {
        "key": 1446336000000,
        "doc_count": 3,
        "hits": {
          "hits": {
            "total": 3,
            "max_score": 1,
            "hits": [
              {
                "_index": "t123",
                "_type": "t123type1",
                "_id": "5",
                "_score": 1,
                "_source": {
                  "objectId": "5",
                  "objectIndexId": 123,
                  "record": {
                    "status": "Opened",
                    "typeName": "type1",
                    "openedDate": 1446336000000
                  },
                  "oId": 123,
                  "objectIndexType": "t123type1"
                }
              },
              {
                "_index": "t123",
                "_type": "t123type1",
                "_id": "2",
                "_score": 1,
                "_source": {
                  "objectId": "2",
                  "objectIndexId": 123,
                  "record": {
                    "status": "Opened",
                    "typeName": "type1",
                    "openedDate": 1446336000000
                  },
                  "oId": 123,
                  "objectIndexType": "t123type1"
                }
              },
              {
                "_index": "t123",
                "_type": "t123type2",
                "_id": "4",
                "_score": 1,
                "_source": {
                  "objectId": "4",
                  "objectIndexId": 123,
                  "record": {
                    "status": "Opened",
                    "typeName": "type2",
                    "openedDate": 1446336000000
                  },
                  "oId": 123,
                  "objectIndexType": "t123type2"
                }
              }
            ]
          }
        },
        "byType": {
          "doc_count_error_upper_bound": 0,
          "sum_other_doc_count": 0,
          "buckets": []
        }
      }
    ]
  }
}
```

---

<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:30pm UTC](https://discuss.elastic.co/t/buckets-empty-in-aggregates/37379/6 "2017-07-05T23:30:09Z")

</div>


