# Date\_histogram aggregation combined with sum aggregation

**URL:** <https://discuss.elastic.co/t/date-histogram-aggregation-combined-with-sum-aggregation/96621>\
**Category:** Elasticsearch\
**Created:** [August 10, 2017, 1:27pm UTC](https://discuss.elastic.co/t/date-histogram-aggregation-combined-with-sum-aggregation/96621 "2017-08-10T13:27:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![daveli](https://avatars.discourse-cdn.com/v4/letter/d/5f9b8f/32.png) [@daveli](https://discuss.elastic.co/u/daveli)\
**Post date:** [August 10, 2017, 1:27pm UTC](https://discuss.elastic.co/t/date-histogram-aggregation-combined-with-sum-aggregation/96621/1 "2017-08-10T13:27:58Z")

</div>

Hello all!

I'm trying to do a date\_histogram along with a sum aggregation but this returns the value 0 on the sum.

Query:

```auto
{
  "size": 0,
  "query": {
    "bool": {
      "filter": {
        "term": {
          "articleId.keyword": "7r2KB"
        }
      }
    }
  }, 
  "aggs": {
    "total_reading_time": {
      "sum": {
        "field": "duration"
      }
    },
    "dates": {
      "date_histogram": {
        "field": "viewDate",
        "interval": "10m",
        "min_doc_count": 1
      },
      "aggs": {
        "reading_time": {
          "sum": {
            "field": "duration"
          }
        }
      }
    }
  }
}

```

Somehow the sum (total\_reading\_time) works, yet aggregated using date\_histogram (reading\_time) doesn't. I'm using ES 5.3 on AWS.

Hope someone can help me out 😄

---

<div class="post-metadata">

**Author:** ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)\
**Post date:** [August 18, 2017, 2:53pm UTC](https://discuss.elastic.co/t/date-histogram-aggregation-combined-with-sum-aggregation/96621/2 "2017-08-18T14:53:43Z")

</div>

Can you paste the results? If the sum of `reading_time` is zero, that means there were no documents (or no documents with the field `duration` in the bucketed interval.

`reading_time` will give you a sum of `duration` per-interval, so if the interval is empty, you won't have a sum.

---

<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:** [September 15, 2017, 2:53pm UTC](https://discuss.elastic.co/t/date-histogram-aggregation-combined-with-sum-aggregation/96621/3 "2017-09-15T14:53:56Z")

</div>

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