Date histogram doesn't create buckets for dates later than the last record found, even with 'extended_bounds' min value of 0. How do I fix this?

I am trying to create a chart with the sum of a value in records I have. The date buckets should be categorized by weeks, and they should include a sum of the 'time' value in each record. To test this I inserted 10 million+ records with the latest date of 2018-12-31. Then, I created a query hoping for data separated by weeks. But, I realized that the way I was doing it was not going to show buckets for weeks that had no data. Unfortunately I need this, so I found the 'extended_bounds' key. Using this it's generated records starting all the way at 1970, even if the sum is 0. The problem is, they don't go all the way up to the current date. They only go up to the date of the last records (2018-12-24). Does anyone have any idea how I can get the buckets to include weeks all the way up to the current date?

The params look like this.

{
  "index": "index_name",
  "body": {
    "query": {
      "bool": {
        "must": [
          {
            "range": {
              "timestamp": {
                "gte": "2012-01-01T00:00:00+00:00",
                "lte": "2019-09-01T00:00:00+00:00"
              }
            }
          },
          {
            "term": {
              "user_id": "1"
            }
          }
        ]
      }
    },
    "aggs": {
      "records_per_interval": {
        "date_histogram": {
          "field": "timestamp",
          "interval": "week",
          "extended_bounds": {
            "min": 0
          }
        },
        "aggs": {
          "time": {
            "sum": {
              "field": "time"
            }
          }
        }
      }
    }
  }
}

The buckets go all the way from 1969-12-29T00:00:00.000Z to 2018-12-24T00:00:00.000Z. I need them between the GTE and LTE values though. I can filter through the buckets that are not inside those dates, but I need empty buckets for the weeks in between 2018-12-24 and today.

Does anyone have any idea how to do this? Surely this isn't the way this is supposed to work.

Update the extended_bounds to below:

"records_per_interval": {
        "date_histogram": {
          "field": "timestamp",
          "interval": "week",
          "extended_bounds": {
            "min": "2012-01-01T00:00:00+00:00",
            "max":"2019-09-01T00:00:00+00:00"
          }
        }

Wow that worked perfectly. I guess the min was for the date on the bucket not the sum. That makes sense. Thanks!

Yes you got it right , min is for date_histogram in the above.

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