Date_histogram aggregation combined with sum aggregation


(Dave Li) #1

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:

{
  "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 :smile:


(Zachary Tong) #2

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.


(system) #3

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