Is it possible to some how combine sum with cardinality

Hi all,
I'd like to get a sum of a document using cardinality, but since I can't have sub-aggregation either for the sum or cardinality. How can I do this? is there any alternative?
i.e

 {
  "size": 0,
  "aggs": {
    "search": {
      "aggs": {
        "values": {
          "terms": {
            "field": "desired_field",
            "size": 100,
            "order": {
              "_count": "desc"
            }
          },
          "aggs": {
            "sum_field": {
              "sum": {
                "field": "wECHQM"
              },
              "aggs": {
                "cardinality": {
                  "cardinality": {
                    "field": "cardinality_field"
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

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