# Aggregation with null values

**URL:** <https://discuss.elastic.co/t/aggregation-with-null-values/65867>\
**Category:** Elasticsearch\
**Created:** [November 12, 2016, 8:34am UTC](https://discuss.elastic.co/t/aggregation-with-null-values/65867 "2016-11-12T08:34:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shashi-GS](https://avatars.discourse-cdn.com/v4/letter/s/13edae/32.png) [@Shashi-GS](https://discuss.elastic.co/u/Shashi-GS)\
**Post date:** [November 12, 2016, 8:34am UTC](https://discuss.elastic.co/t/aggregation-with-null-values/65867/1 "2016-11-12T08:34:17Z")

</div>

Is there any way I can get the aggregation with null values?

My Data look like this.

```
 {"system": "aaa"},
{"system": "bbb"},
{"system": null}

```

My aggregation query looks like this

```
{
    "aggs" : {
        "myAggrs" : {
            "terms" : { "field" : "system" }
        } 
}

```

Expected result is

```
{
   "key": "aaa",
   "doc_count": 1
},
{
   "key": "bbb",
   "doc_count": 1
},
{
   "key": null,
   "doc_count": 1
}
```

---

<div class="post-metadata">

**Author:** ![danielmitterdorfer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielmitterdorfer/32/110510_2.png) [@danielmitterdorfer](https://discuss.elastic.co/u/danielmitterdorfer)\
**Post date:** [November 14, 2016, 9:38am UTC](https://discuss.elastic.co/t/aggregation-with-null-values/65867/2 "2016-11-14T09:38:55Z")

</div>

Hi @Shashi-GS,

you can specify [`missing`](https://www.elastic.co/guide/en/elasticsearch/reference/2.4/search-aggregations-bucket-terms-aggregation.html#_missing_value_12) in your terms aggregation, e.g.:

```auto
{
    "aggs" : {
        "myAggrs" : {
            "terms" : { "field" : "system" },
            "missing": "N/A"
        } 
}

```

Daniel

---

<div class="post-metadata">

**Author:** ![Shashi-GS](https://avatars.discourse-cdn.com/v4/letter/s/13edae/32.png) [@Shashi-GS](https://discuss.elastic.co/u/Shashi-GS)\
**Post date:** [November 14, 2016, 5:58pm UTC](https://discuss.elastic.co/t/aggregation-with-null-values/65867/3 "2016-11-14T17:58:31Z")

</div>

Thank you for the response. No actually this will give you the result of separate section of missing count from the aggregation. Hence I don't want to use this. I found the solution for this problem,

While storing the data will use "null\_value":"null". From this I can get the aggregation result with null values as well . As per my expectation.

---

<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:** [December 12, 2016, 5:58pm UTC](https://discuss.elastic.co/t/aggregation-with-null-values/65867/4 "2016-12-12T17:58:31Z")

</div>

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