title: Getting the total count of all the documents in buckets
body: <p>When I'm searching by the following aggregation: </p>
  
  <pre><code>"aggregations": {
  "codes": {
    "terms": {
      "field": "code"
    },
    "aggs": {
      "dates": {
        "date_range": {
          "field": "created_time",
          "ranges": [
            {
              "from": "2017-12-06T00:00:00.000",
              "to": "2017-12-06T16:00:00.000"
            },
            {
              "from": "2017-12-07T00:00:00.000",
              "to": "2017-12-07T23:59:59.999"
            }
          ]
        }
      }
    }
  }
  }
  </code></pre>
  
  <p>I get the following result: </p>
  
  <pre><code>"aggregations": {
  "codes": {
    "buckets": [
      {
        "key": "123456",
        "doc_count": 104005499,
        "dates": {
          "buckets": [
            {
              "key": "2017-12-05T20:00:00.000Z-2017-12-06T12:00:00.000Z",
              "from_as_string": "2017-12-05T20:00:00.000Z",
              "to_as_string": "2017-12-06T12:00:00.000Z",
              "doc_count": 156643
            },
            {
              "key": "2017-12-06T20:00:00.000Z-2017-12-07T19:59:59.999Z",
              "from_as_string": "2017-12-06T20:00:00.000Z",
              "to_as_string": "2017-12-07T19:59:59.999Z",
              "doc_count": 11874
            }
          ]
        }
      },
      ...
    ]
   }
  }
  </code></pre>
  
  <p>So now I have a list of buckets of buckets. I need to have a total count value for each bucket, which is the sum of <code>doc_counts</code> of the buckets inside. For example, the total count for my first bucket should be 156643 + 11874 = 168517.
  I've tried using Sub Bucket aggregation, but</p>
  
  <pre><code> "totalcount": {
        "sum_bucket": {
          "buckets_path": "dates"
        }
      }
  </code></pre>
  
  <p>this is not going to work, because <code>"buckets_path must reference either a number value or a single value numeric metric aggregation, got: org.elasticsearch.search.aggregations.bucket.range.date.InternalDateRange.Bucket"</code>. Any ideas how should I do this?</p>