# Total doc\_count aggregations

**URL:** <https://discuss.elastic.co/t/total-doc-count-aggregations/293832>\
**Category:** Elasticsearch\
**Created:** [January 9, 2022, 9:01pm UTC](https://discuss.elastic.co/t/total-doc-count-aggregations/293832 "2022-01-09T21:01:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Miguel\_BA](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/miguel_ba/32/46926_2.png) [@Miguel\_BA](https://discuss.elastic.co/u/Miguel_BA)\
**Post date:** [January 9, 2022, 9:01pm UTC](https://discuss.elastic.co/t/total-doc-count-aggregations/293832/1 "2022-01-09T21:01:22Z")

</div>

I am looking for a way to sum up the Total **doc\_count** aggregations that I have defined in the query. I will try to explain my question through the following simple representative example:

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

```

Query:

```auto
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".

```auto
  "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**?  
If I get the total doc\_count, it would reduce a lot of GET in the process of querying the data.  
I've been trying to do it with script but since they are boolean values it doesn't work.

---

<div class="post-metadata">

**Author:** ![Tomo\_M](https://avatars.discourse-cdn.com/v4/letter/t/848f3c/32.png) [@Tomo\_M](https://discuss.elastic.co/u/Tomo_M)\
**Post date:** [January 10, 2022, 9:11am UTC](https://discuss.elastic.co/t/total-doc-count-aggregations/293832/2 "2022-01-10T09:11:05Z")

</div>

Hi,

You may obtain the value by using [Sum Bucket Aggregation](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-sum-bucket-aggregation.html).

But with the shared query, I suppose documents with 'name' == false AND 'surname' ==false will match and doc\_count in 'name' aggregation and doc\_count in 'surname' aggregation must be the same. Is it your intent?  
If you want to query OR, you may use "should" clause and "minimum\_should\_match" parameter in Boolean query.

---

<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:** [February 7, 2022, 9:11am UTC](https://discuss.elastic.co/t/total-doc-count-aggregations/293832/3 "2022-02-07T09:11:42Z")

</div>

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