# Pipelined bucket aggregation

**URL:** https://discuss.elastic.co/t/pipelined-bucket-aggregation/329989
**Category:** Elasticsearch
**Tags:** ingest-pipeline
**Created:** [April 14, 2023, 9:38am UTC](https://discuss.elastic.co/t/pipelined-bucket-aggregation/329989 "2023-04-14T09:38:56Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![HansPeterSloot](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hanspetersloot/32/51132_2.png) [@HansPeterSloot](https://discuss.elastic.co/u/HansPeterSloot)
#### Post date: [April 14, 2023, 9:38am UTC](https://discuss.elastic.co/t/pipelined-bucket-aggregation/329989/1 "2023-04-14T09:38:56Z")

</div>

Hello  
I am ingesting logs from different servers into elastic and want to be alerted when a server suddenly stops sending data.

For this I have come up with this aggregation:

```auto
GET .xxxt*/_search?size=0
{
  "query": {
    "bool": {
      "filter": [
        {
          "range": {
            "@timestamp": {
              "gte": "now-31d"
            }
          }
        }
      ]
    }
  },
  "aggs": {
    "hostnames": {
      "terms": {
        "field": "server",
        "size": 10
      },
      "aggs": {
        "docs_per_5m": {
          "date_range": {
            "field": "@timestamp",
            "ranges": [
              {
                "to": "now"
              },
              {
                "from": "now-5m"
              }
            ]
          },
          "aggs": {
            "last_bucket": {
              "bucket_sort": {
                "sort": [
                  {
                    "_key": {
                      "order": "desc"
                    }
                  }
                ],
                "size": 1,
                "gap_policy": "insert_zeros"
              }
            }
          }
        }
      }
    }
  }
}

```

This yields the following output:

```auto
  "aggregations": {
    "hostnames": {
...................
      "buckets": [
        {
          "key": "server1",
          "doc_count": 18684883,
          "docs_per_5m": {
            "buckets": [
              {
                "key": "2023-04-14T09:28:04.900Z-*",
                "from": 1681464484900,
                "from_as_string": "2023-04-14T09:28:04.900Z",
                "doc_count": 2128
              }
            ]
          }
        },
        {
          "key": "server2",
          "doc_count": 761066,
          "docs_per_5m": {
            "buckets": [
              {
                ............
                "doc_count": 47
              }
            ]
          }
        },
        {
          "key": "server3",
          "doc_count": 66066,
          "docs_per_5m": {
            "buckets": [
              {
................................
                "doc_count": 7
              }
            ]
          }
        },
        {
          "key": "server4",
          "doc_count": 14,
          "docs_per_5m": {
            "buckets": [
              {
.....................",
                "doc_count": 0
              }
            ]
          }
        }
      ]
    }
  }

```

But now I only want to have the buckets with "doc\_count" : 0  
Since I want to use it for a watcher that alerts when there is a server with 0 documents for the last 5 minutes.

I am getting frustrated 😠

---

<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: [May 12, 2023, 9:39am UTC](https://discuss.elastic.co/t/pipelined-bucket-aggregation/329989/2 "2023-05-12T09:39:40Z")

</div>

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