'ELASTICSEARCH - Total doc_count aggregations

I am looking for a way to sum up the total of an aggregation that I have defined in the query. For example:

  {
      "name" : false,
      "surname" : false
    
  },
  {
      "name" : false,
      "surname" : false
  }

Query:

GET index/_search?size=0
{"query": {
  "bool": {
    "must": [
      {"term": {"name": false}},
      {"term": {"surname": false}}
    ]
  }
},
  "aggs": {
    "name": {
      "terms": {
        "field": "name"
      }
    },
    "surname": {
      "terms": {
        "field": "surname"
      }
    }
  }
}

The query returns the value for each field "name" and "surname" with value "false".

  "aggregations" : {
    "name" : {
      "doc_count_error_upper_bound" : 0,
      "sum_other_doc_count" : 0,
      "buckets" : [
        {
          "key" : 0,
          "key_as_string" : "false",
          "doc_count" : 2 <---------
        }
      ]
    },
    "surname" : {
      "doc_count_error_upper_bound" : 0,
      "sum_other_doc_count" : 0,
      "buckets" : [
        {
          "key" : 0,
          "key_as_string" : "false",
          "doc_count" : 2 <---------
        }
      ]
    }
  }
}

Is it possible to return the total sum of doc_count, so that in this situation it would be "doc_count" : 2 + "doc_count" : 2 == 4?

I've been trying to do it with script but since they are boolean values it doesn't work.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source