# How to aggregate nested fields with null values?

**URL:** <https://discuss.elastic.co/t/how-to-aggregate-nested-fields-with-null-values/199536>\
**Category:** Elasticsearch\
**Created:** [September 15, 2019, 1:10pm UTC](https://discuss.elastic.co/t/how-to-aggregate-nested-fields-with-null-values/199536 "2019-09-15T13:10:14Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Doronpt](https://avatars.discourse-cdn.com/v4/letter/d/898d66/32.png) [@Doronpt](https://discuss.elastic.co/u/Doronpt)\
**Post date:** [September 15, 2019, 1:12pm UTC](https://discuss.elastic.co/t/how-to-aggregate-nested-fields-with-null-values/199536/2 "2019-09-15T13:12:21Z")

</div>

```
GET test/doc/_search
{
  "size": 0,
  "query": {
    "match_all": {}
  },
  "aggs": {
    "my_agg": {
      "nested": {
        "path": "fields"
      },
      "aggs": {
        "my_filter": {
          "filter": {
            "term": {
              "fields.name": "bbb"
            }
          },
          "aggs": {
            "my_term": {
              "terms": {
                "field": "fields.value"
              }
            }
          }
        }
      }
    }
  }
}

```

And the response is:

```
  "aggregations" : {
    "my_agg" : {
      "doc_count" : 4,
      "my_filter" : {
        "doc_count" : 2,
        "my_term" : {
          "doc_count_error_upper_bound" : 0,
          "sum_other_doc_count" : 0,
          "buckets" : [
            {
              "key" : 2,
              "doc_count" : 2
            }
          ]
        }
      }
    }
  }

```

I want to get also:

"key" : 0 (for N/A)  
"doc\_count" : 1

---

_[View the full topic](https://discuss.elastic.co/t/how-to-aggregate-nested-fields-with-null-values/199536)._
