Include empty nested fields in aggregation

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

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:

"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:

"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.

Looks like it has been asked already but no answer How to aggregate nested fields with null values? - #2 by Doronpt

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

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

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