# Include empty nested fields in aggregation

**URL:** <https://discuss.elastic.co/t/include-empty-nested-fields-in-aggregation/288003>\
**Category:** Elasticsearch\
**Created:** [October 29, 2021, 1:31pm UTC](https://discuss.elastic.co/t/include-empty-nested-fields-in-aggregation/288003 "2021-10-29T13:31:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Calin\_Blaga](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/calin_blaga/32/96516_2.png) [@Calin\_Blaga](https://discuss.elastic.co/u/Calin_Blaga)\
**Post date:** [October 29, 2021, 1:31pm UTC](https://discuss.elastic.co/t/include-empty-nested-fields-in-aggregation/288003/1 "2021-10-29T13:31:31Z")

</div>

I would like to do an aggregation on a nested field, and I would like to include empty occurrences too.  
What I tried:

```auto
GET index/_search
{
  "size": 0,
  "aggs": {
    "language_skills": {
      "nested": {
        "path": "language_skills"
      },
      "aggs": {
        "result": {
          "terms": {
            "field": "language_skills.language",
            "missing": "N/A"
          }
        }
      }
    }
  }
}

```

what I get:

```auto
"aggregations" : {
    "language_skills" : {
      "doc_count" : 157,
      "result" : {
        "doc_count_error_upper_bound" : 0,
        "sum_other_doc_count" : 0,
        "buckets" : [
          {
            "key" : "de",
            "doc_count" : 73
          },
          {
            "key" : "en",
            "doc_count" : 62
          },
          {
            "key" : "fr",
            "doc_count" : 19
          },
          {
            "key" : "it",
            "doc_count" : 3
          }
        ]
      }
    }
  }

```

What I expect:

```auto
"aggregations": {
  "language_skills": {
    "doc_count": 157,
    "result": {
      "doc_count_error_upper_bound": 0,
      "sum_other_doc_count": 0,
      "buckets": [
        {
          "key": "de",
          "doc_count": 73
        },
        {
          "key": "en",
          "doc_count": 62
        },
        {
          "key": "fr",
          "doc_count": 19
        },
        {
          "key": "it",
          "doc_count": 3
        },
        {
          "key": "N/A", <---- this bucket is missing
          "doc_count": 21
        }
      ]
    }
  }
}

```

Tried some other queries as well, with no luck.  
Any help would be highly appreciated.

---

<div class="post-metadata">

**Author:** ![Calin\_Blaga](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/calin_blaga/32/96516_2.png) [@Calin\_Blaga](https://discuss.elastic.co/u/Calin_Blaga)\
**Post date:** [November 1, 2021, 8:13am UTC](https://discuss.elastic.co/t/include-empty-nested-fields-in-aggregation/288003/2 "2021-11-01T08:13:52Z")

</div>

Looks like it has been asked already but no answer [How to aggregate nested fields with null values? - #2 by Doronpt](https://discuss.elastic.co/t/how-to-aggregate-nested-fields-with-null-values/199536/2)

---

<div class="post-metadata">

**Author:** ![Calin\_Blaga](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/calin_blaga/32/96516_2.png) [@Calin\_Blaga](https://discuss.elastic.co/u/Calin_Blaga)\
**Post date:** [November 2, 2021, 11:37am UTC](https://discuss.elastic.co/t/include-empty-nested-fields-in-aggregation/288003/3 "2021-11-02T11:37:40Z")

</div>

Tried this too, but it returns the whole result instead of what is expected:

```auto
GET index/_search
{
  "size": 0, 
  "aggs": {
    "language": {
      "nested": {
        "path": "language_skills"
      },
      "aggs": {
        "language": {
          "missing": {
            "field": "language_skills.language"
          }
        }
      }
    }
  }
}

```

---

<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:** [November 30, 2021, 11:37am UTC](https://discuss.elastic.co/t/include-empty-nested-fields-in-aggregation/288003/4 "2021-11-30T11:37:52Z")

</div>

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