# Average Aggregation over two fields

**URL:** <https://discuss.elastic.co/t/average-aggregation-over-two-fields/247516>\
**Category:** Elasticsearch\
**Created:** [September 4, 2020, 10:14am UTC](https://discuss.elastic.co/t/average-aggregation-over-two-fields/247516 "2020-09-04T10:14:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel\_Garcia](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/daniel_garcia/32/75104_2.png) [@Daniel\_Garcia](https://discuss.elastic.co/u/Daniel_Garcia)\
**Post date:** [September 4, 2020, 10:14am UTC](https://discuss.elastic.co/t/average-aggregation-over-two-fields/247516/1 "2020-09-04T10:14:10Z")

</div>

What I would like to achieve is, given this type of docs:

```auto
    {
      "my_index": {
        "mappings": {
          "result": {
            "dynamic": "false",
            "_all": {
              "enabled": false
            },
            "properties": {
              "finales": {
                "properties": {
                  "attempts": {
                    "type": "integer"
                  },
                  "reattempts": {
                    "type": "integer"
                  }
                }
              }
          }
        }
      }
    }

```

is a query with an aggregation to calculate a _reattempts_ rate:

`avg(reattempts/attempts)`

I've tried several options, but I'm not able to do it for two fields.

So, for each document I need to calculate de rate `reattempts/attempts`, and over this apply the average.

What I've achieved so far is to calculate `avg(reattempts)/avg(attempts)`, but that's not what I exactly need.

---

<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:** [October 2, 2020, 10:14am UTC](https://discuss.elastic.co/t/average-aggregation-over-two-fields/247516/2 "2020-10-02T10:14:24Z")

</div>

Closed on October 2, 2020, 10:14am UTC

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