# Elasticsearch null values aggregation

**URL:** <https://discuss.elastic.co/t/elasticsearch-null-values-aggregation/237828>\
**Category:** Elasticsearch\
**Created:** [June 19, 2020, 3:26pm UTC](https://discuss.elastic.co/t/elasticsearch-null-values-aggregation/237828 "2020-06-19T15:26:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hiba](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hiba/32/110919_2.png) [@hiba](https://discuss.elastic.co/u/hiba)\
**Post date:** [June 19, 2020, 3:26pm UTC](https://discuss.elastic.co/t/elasticsearch-null-values-aggregation/237828/1 "2020-06-19T15:26:00Z")

</div>

Hi ,  
is null values considered a correct value for AVG aggregation in elasticsearch ?

example  
a=5  
b=15  
c=0  
avg =(5+15+0)/3  
or  
avg=(5+15)/2

any help pease!

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 19, 2020, 3:57pm UTC](https://discuss.elastic.co/t/elasticsearch-null-values-aggregation/237828/2 "2020-06-19T15:57:11Z")

</div>

I believe the answer is easy to get:

```auto
DELETE average
PUT average/_doc/1
{
  "foo": "bar", 
  "value": 5
}
PUT average/_doc/2
{
  "foo": "bar", 
  "value": 15
}
PUT average/_doc/3
{
  "foo": "bar"
}
GET average/_search
{
  "size": 0,
  "aggs": {
    "avg": {
      "avg": {
        "field": "value"
      }
    }
  }
}

```

Gives

```auto
{
  "took" : 3,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 3,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : []
  },
  "aggregations" : {
    "avg" : {
      "value" : 10.0
    }
  }
}

```

But with value = 0 (which is not null value):

```auto
PUT average/_doc/3
{
  "foo": "bar",
  "value": 0
}
GET average/_search
{
  "size": 0,
  "aggs": {
    "avg": {
      "avg": {
        "field": "value"
      }
    }
  }
}

```

This gives:

```auto
{
  "took" : 147,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 3,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : []
  },
  "aggregations" : {
    "avg" : {
      "value" : 6.666666666666667
    }
  }
}

```

---

<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:** [July 17, 2020, 3:57pm UTC](https://discuss.elastic.co/t/elasticsearch-null-values-aggregation/237828/3 "2020-07-17T15:57:19Z")

</div>

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