# Cross-aggregartion calculation

**URL:** <https://discuss.elastic.co/t/cross-aggregartion-calculation/110963>\
**Category:** Elasticsearch\
**Created:** [December 10, 2017, 9:39am UTC](https://discuss.elastic.co/t/cross-aggregartion-calculation/110963 "2017-12-10T09:39:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gilisade](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gilisade/32/98740_2.png) [@gilisade](https://discuss.elastic.co/u/gilisade)\
**Post date:** [December 10, 2017, 9:39am UTC](https://discuss.elastic.co/t/cross-aggregartion-calculation/110963/1 "2017-12-10T09:39:02Z")

</div>

hi  
I have 4 aggregations - each runs on a different field.

```
  "aggs": {
    "URL_1": {
      "terms": {
        "field": "URL_1",
        "size": 1000
      },"aggs": {
        "src_count": {
          "cardinality": {
            "field": "src"
          }
        }
      }
    },
    "URL_2": {
      "terms": {
        "field": "URL_2",
        "size": 1000
      },"aggs": {
        "src_count": {
          "cardinality": {
            "field": "src"
          }
        }
      }
    },
    "URL_3": {
      "terms": {
        "field": "URL_3",
        "size": 1000
      },"aggs": {
        "src_count": {
          "cardinality": {
            "field": "src"
          }
        }
      }
    },
    "URL_4": {
      "terms": {
        "field": "URL_4",
        "size": 1000
      },"aggs": {
        "src_count": {
          "cardinality": {
            "field": "src"
          }
        }
      }
    }
}
}

```

sometimes I get the same urls in the different aggs  
that means that the same key can be found in both URL\_1 and URL\_2 (or more) with different values in the src\_count.

i need to create a "Master" aggregations that calculates the sum of src\_count for each key on all 4 aggregations .

is there a way of doing that ?

using ES 5.5  
Tnx

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [December 12, 2017, 10:27am UTC](https://discuss.elastic.co/t/cross-aggregartion-calculation/110963/2 "2017-12-12T10:27:54Z")

</div>

> [@gilisade](#):
>
> is there a way of doing that ?

Either reindex and look at the `copy_to` [1] mapping to put urls 1 to 4 in a new combined "urls" field or use a single terms agg and use a script [2] to fuse urls 1 to 4 into a new array on the fly

[1] [copy\_to | Elasticsearch Guide [8.11] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/copy-to.html)  
[2] [Terms aggregation | Elasticsearch Guide [8.11] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html#search-aggregations-bucket-terms-aggregation-script)

---

<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:** [January 9, 2018, 10:27am UTC](https://discuss.elastic.co/t/cross-aggregartion-calculation/110963/3 "2018-01-09T10:27:55Z")

</div>

Closed on January 9, 2018, 10:27am UTC

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