# Average aggregation across all available fields

**URL:** <https://discuss.elastic.co/t/average-aggregation-across-all-available-fields/92131>\
**Category:** Elasticsearch\
**Created:** [July 6, 2017, 3:50pm UTC](https://discuss.elastic.co/t/average-aggregation-across-all-available-fields/92131 "2017-07-06T15:50:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheTannerRyan](https://avatars.discourse-cdn.com/v4/letter/t/ba9def/32.png) [@TheTannerRyan](https://discuss.elastic.co/u/TheTannerRyan)\
**Post date:** [July 6, 2017, 3:50pm UTC](https://discuss.elastic.co/t/average-aggregation-across-all-available-fields/92131/1 "2017-07-06T15:50:19Z")

</div>

Hello,

I was wondering if anyone knows how to perform average aggregations across all fields available in a record.

I have a setup where I have sensors, and I would like to take the average values of each field, without specifying each individual field.

Right now, this is what my query looks like:

```
{
  "size": 0,
  "query": {
    "range" : {
        "datetime" : {
            "gte": "2017-07-05T00:00:00", 
            "lte": "now" 
        }
    }
  },
  "aggs": {
    "dates": {
      "date_histogram": {
        "field": "datetime",
        "interval": "4h"
      },
      "aggs": {
        "sensors": {
          "terms": {
            "field": "sensorInfo.location.keyword",
            "size": 1000
          }
        }
      }
    }
  }
}

```

It first selects a range of data, then splits that range into specific time intervals (4 hours). From there, I split each time interval into the different sensors that I have.

E.g. In 4:00pm bucket, I have sensor 1, sensor 2 and sensor 3.

Although I can simply add an average aggregation within the sensor aggregation, I would have to specify each field manually.

```
...
"aggs": {
  "sensors": {
    "terms": {
      "field": "sensorInfo.location.keyword",
      "size": 1000
    },
    "aggs": {
      "avg_temp": {
        "avg": {
          "field": "temperature"
        }
      },
      "avg_rh": {
        "avg": {
          "field": "humidity"
        }
      },
      ...
    }
  }
}
...

```

Is there any way that I am able to have an average of each field in sensor taken, without the need of specifying each one?

Thanks!

---

<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:** [August 3, 2017, 3:50pm UTC](https://discuss.elastic.co/t/average-aggregation-across-all-available-fields/92131/2 "2017-08-03T15:50:21Z")

</div>

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