# Aggregating over histogram buckets

**URL:** <https://discuss.elastic.co/t/aggregating-over-histogram-buckets/107559>\
**Category:** Elasticsearch\
**Created:** [November 14, 2017, 2:29pm UTC](https://discuss.elastic.co/t/aggregating-over-histogram-buckets/107559 "2017-11-14T14:29:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mike\_Nielsen](https://avatars.discourse-cdn.com/v4/letter/m/8e8cbc/32.png) [@Mike\_Nielsen](https://discuss.elastic.co/u/Mike_Nielsen)\
**Post date:** [November 14, 2017, 2:29pm UTC](https://discuss.elastic.co/t/aggregating-over-histogram-buckets/107559/1 "2017-11-14T14:29:32Z")

</div>

Hi,

I'm just new to writing elastic queries. I have the following, but would like to count the number of histogram buckets, per host, that have a count of 0, and I can't quite seem to get it across the line.

I'll have another cup of coffee and try again, but any hints would be gratefully received!

Thanks!

```
GET /metricbeat-prd-2017.11.14/_search
{
  "size": 0,
  "aggs": {
    "per_host": {
      "aggs": {
        "per_minute": {
          "date_histogram": {
            "field": "@timestamp",
            "interval": "10s"
          }
        }
      },
      "terms": {
        "size": 10,
        "field": "beat.hostname"
      }
    }
  },
  "query": {
    "bool": {
      "filter": [
        {
          "regexp": {
            "beat.hostname": "appserver[12]"
          }
        },
        {
          "term": {
            "metricset.name": "process"
          }
        },
        {
          "term": {
            "system.process.username": "wildfly"
          }
        },
        {
          "range": {
            "@timestamp": {
              "lte": "now",
              "gte": "now-2m/m"
            }
          }
        }
      ]
    }
  }
}
```

---

<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 12, 2017, 2:29pm UTC](https://discuss.elastic.co/t/aggregating-over-histogram-buckets/107559/2 "2017-12-12T14:29:35Z")

</div>

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