DateHistogram offset does not work when empty buckets

I'm trying to build date histogram for 3 months with interval by 7 days. I know that intervals are started from 1970-01-01 so I use the offset +2d. There is no data in this period, but my buckets start from 2016-12-29 because it is Thursday like 1970-01-01. I just want to my first bucket start from the first date of period
Tested on elastic 5.2.2 and 5.4.0

The problem started from this topic

Query

{
  "size" : 0,
  "query" : {
    "bool" : {
      "filter" : [
        {
          "terms" : {
            "doc.accountNumber" : [
              "1234567890"
            ],
            "boost" : 1.0
          }
        },
        {
          "range" : {
            "doc.dateExecute" : {
              "from" : "2017-02-01",
              "to" : "2017-03-31",
              "include_lower" : true,
              "include_upper" : true,
              "time_zone" : "UTC",
              "boost" : 1.0
            }
          }
        }
      ],
      "disable_coord" : false,
      "adjust_pure_negative" : true,
      "boost" : 1.0,
      "_name" : "onDates"
    }
  },
  "aggregations" : {
    "time" : {
      "date_histogram" : {
        "field" : "doc.dateExecute",
        "format" : "yyyy-MM-dd",
        "time_zone" : "UTC",
        "interval" : "7d",
        "offset" : "+2d",
        "order" : {
          "_key" : "asc"
        },
        "keyed" : false,
        "min_doc_count" : 0,
        "extended_bounds" : {
          "min" : "2017-01-01",
          "max" : "2017-03-31"
        }
      },
      "aggregations" : {
        "incomingAmount" : {
          "sum" : {
            "field" : "doc.incomingAmount"
          }
        },
        "outgoingAmount" : {
          "sum" : {
            "field" : "doc.outgoingAmount"
          }
        }
      }
    }
  }
}

Result

{
  "took": 2,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 0,
    "max_score": 0,
    "hits": []
  },
  "aggregations": {
    "time": {
      "buckets": [
        {
          "key_as_string": "2016-12-29",
          "key": 1482969600000,
          "doc_count": 0,
          "incomingAmount": {
            "value": 0
          },
          "outgoingAmount": {
            "value": 0
          }
        },
        {
          "key_as_string": "2017-01-05",
          "key": 1483574400000,
          "doc_count": 0,
          "incomingAmount": {
            "value": 0
          },
          "outgoingAmount": {
            "value": 0
          }
        },
        {
          "key_as_string": "2017-01-12",
          "key": 1484179200000,
          "doc_count": 0,
          "incomingAmount": {
            "value": 0
          },
          "outgoingAmount": {
            "value": 0
          }
        },
        {
          "key_as_string": "2017-01-19",
          "key": 1484784000000,
          "doc_count": 0,
          "incomingAmount": {
            "value": 0
          },
          "outgoingAmount": {
            "value": 0
          }
        },
        {
          "key_as_string": "2017-01-26",
          "key": 1485388800000,
          "doc_count": 0,
          "incomingAmount": {
            "value": 0
          },
          "outgoingAmount": {
            "value": 0
          }
        },
        {
          "key_as_string": "2017-02-02",
          "key": 1485993600000,
          "doc_count": 0,
          "incomingAmount": {
            "value": 0
          },
          "outgoingAmount": {
            "value": 0
          }
        },
        {
          "key_as_string": "2017-02-09",
          "key": 1486598400000,
          "doc_count": 0,
          "incomingAmount": {
            "value": 0
          },
          "outgoingAmount": {
            "value": 0
          }
        },
        {
          "key_as_string": "2017-02-16",
          "key": 1487203200000,
          "doc_count": 0,
          "incomingAmount": {
            "value": 0
          },
          "outgoingAmount": {
            "value": 0
          }
        },
        {
          "key_as_string": "2017-02-23",
          "key": 1487808000000,
          "doc_count": 0,
          "incomingAmount": {
            "value": 0
          },
          "outgoingAmount": {
            "value": 0
          }
        },
        {
          "key_as_string": "2017-03-02",
          "key": 1488412800000,
          "doc_count": 0,
          "incomingAmount": {
            "value": 0
          },
          "outgoingAmount": {
            "value": 0
          }
        },
        {
          "key_as_string": "2017-03-09",
          "key": 1489017600000,
          "doc_count": 0,
          "incomingAmount": {
            "value": 0
          },
          "outgoingAmount": {
            "value": 0
          }
        },
        {
          "key_as_string": "2017-03-16",
          "key": 1489622400000,
          "doc_count": 0,
          "incomingAmount": {
            "value": 0
          },
          "outgoingAmount": {
            "value": 0
          }
        },
        {
          "key_as_string": "2017-03-23",
          "key": 1490227200000,
          "doc_count": 0,
          "incomingAmount": {
            "value": 0
          },
          "outgoingAmount": {
            "value": 0
          }
        },
        {
          "key_as_string": "2017-03-30",
          "key": 1490832000000,
          "doc_count": 0,
          "incomingAmount": {
            "value": 0
          },
          "outgoingAmount": {
            "value": 0
          }
        }
      ]
    }
  }
}

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