# Why do I get empty buckets when I aggregate on nested field?

**URL:** <https://discuss.elastic.co/t/why-do-i-get-empty-buckets-when-i-aggregate-on-nested-field/321465>\
**Category:** Elasticsearch\
**Tags:** eql-elastic-query-language\
**Created:** [December 17, 2022, 5:23pm UTC](https://discuss.elastic.co/t/why-do-i-get-empty-buckets-when-i-aggregate-on-nested-field/321465 "2022-12-17T17:23:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![learningelastic](https://avatars.discourse-cdn.com/v4/letter/l/958977/32.png) [@learningelastic](https://discuss.elastic.co/u/learningelastic)\
**Post date:** [December 17, 2022, 5:23pm UTC](https://discuss.elastic.co/t/why-do-i-get-empty-buckets-when-i-aggregate-on-nested-field/321465/1 "2022-12-17T17:23:27Z")

</div>

I'm trying to `count()` the `network.protocol` field when grouped by `network.protocol`. So I tried something like this:

```auto
GET .ds-packetbeat-8.5.3-2022.12.14-000001/_search
{
  "aggs": {
    "network": {
      "nested": {
        "path": "network"
      },
      "aggs": {
        "protocol": {
          "terms":{
            "field": "network.protocol"
          },
          "aggs": {
            "count": {
              "value_count": {
                "field": "network.protocol"
              }
            }
          }
        }
      }
    }
  }
}

```

But this gave me empty buckets like this:

```auto
{
  ...
    "aggregations": {
    "network": {
      "doc_count": 0,
      "protocol": {
        "doc_count_error_upper_bound": 0,
        "sum_other_doc_count": 0,
        "buckets": []
      }
    }
  }
}

```

But I know that there are records where `network.protocol` does have a value because this query returns plenty of results:

```auto
GET .ds-packetbeat-8.5.3-2022.12.14-000001/_search
{
  "query" : {
    "match": {
      "network.protocol": "sip"
    }
  }
}

```

How can I get a count grouped by `network.protocol`?

---

<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:** [January 14, 2023, 5:23pm UTC](https://discuss.elastic.co/t/why-do-i-get-empty-buckets-when-i-aggregate-on-nested-field/321465/2 "2023-01-14T17:23:28Z")

</div>

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