DateHistogram not working as expected

Mapping:

        {
          "test_2e311eff-97c0-4270-b254-0c43cd5f2acc": {
            "mappings": {
              "test_2e311eff-97c0-4270-b254-0c43cd5f2acc_type": {
                "properties": {
                  "2e311eff-97c0-4270-b254-0c43cd5f2accTableLevelStatsFieldInternalRule_Completeness": {
                    "type": "integer"
                  },
                  "_testile_row_id": {
                    "type": "keyword"
                  },
                  "date22": {
                    "type": "date",
                    "format": "yyyy-MM-dd||yyyy-MM-dd'T'HH:mm:ss||yyyy-MM-dd HH:mm:ss||yyyy-MM-dd'T'HH:mm:ss.SSS'Z'||HH:mm:ss||HH:mm:ss.SSS||date_optional_time||epoch_millis"
                  },
                  "datetime22": {
                    "type": "date",
                    "format": "yyyy-MM-dd||yyyy-MM-dd'T'HH:mm:ss||yyyy-MM-dd HH:mm:ss||yyyy-MM-dd'T'HH:mm:ss.SSS'Z'||HH:mm:ss||HH:mm:ss.SSS||date_optional_time||epoch_millis"
                  },
                  "time22": {
                    "type": "date",
                    "format": "yyyy-MM-dd||yyyy-MM-dd'T'HH:mm:ss||yyyy-MM-dd HH:mm:ss||yyyy-MM-dd'T'HH:mm:ss.SSS'Z'||HH:mm:ss||HH:mm:ss.SSS||date_optional_time||epoch_millis"
                  }
                }
              }
            }
          }
        }

Data in index

{
              "_testile_row_id": "1",
              "time22": "10:00:00",
              "datetime22": "2017-09-01T10:00:00"
            }
          },
          {
            "_index": "test_2e311eff-97c0-4270-b254-0c43cd5f2acc",
            "_type": "test_2e311eff-97c0-4270-b254-0c43cd5f2acc_type",
            "_id": "9ZoLUGsBn7EFIldnql5B",
            "_score": 1,
            "_source": {
              "_testile_row_id": "2",
              "time22": "11:09:00",
              "datetime22": "2017-09-02T22:00:00",
              "date22": null
            }
          },
          {
            "_index": "test_2e311eff-97c0-4270-b254-0c43cd5f2acc",
            "_type": "test_2e311eff-97c0-4270-b254-0c43cd5f2acc_type",
            "_id": "9poLUGsBn7EFIldnql5B",
            "_score": 1,
            "_source": {
              "_testile_row_id": "3",
              "time22": "03:09:00",
              "datetime22": "2017-09-02T10:00:00",
              "date22": "2016-09-01"
            }
          },
          {
            "_index": "test_2e311eff-97c0-4270-b254-0c43cd5f2acc",
            "_type": "test_2e311eff-97c0-4270-b254-0c43cd5f2acc_type",
            "_id": "95oLUGsBn7EFIldnql5B",
            "_score": 1,
            "_source": {
              "_testile_row_id": "4",
              "time22": "15:09:00",
              "datetime22": null,
              "date22": "2016-09-01"
            }
          }
        ]
      }
    }

Date histogram aggregation query:

GET test_2e311eff-97c0-4270-b254-0c43cd5f2acc/_search
    {
      "aggs": {
        "Histogram": {
          "date_histogram": {
            "field": "date22",
            "interval": 677376000,
            "offset": 0,
            "order": {
              "_key": "asc"
            },
            "keyed": false,
            "min_doc_count": 0
          }
        }
      }
    }

Response:

{
  "aggregations": {
    "Histogram": {
      "buckets": [
        {
          "key_as_string": "2016-08-31",
          "key": 1472615424000,
          "doc_count": 2
        },
        {
          "key_as_string": "2016-09-08",
          "key": 1473292800000,
          "doc_count": 0
        },
        {
          "key_as_string": "2016-09-15",
          "key": 1473970176000,
          "doc_count": 0
        },
        {
          "key_as_string": "2016-09-23",
          "key": 1474647552000,
          "doc_count": 0
        },
        {
          "key_as_string": "2016-10-01",
          "key": 1475324928000,
          "doc_count": 0
        },
        {
          "key_as_string": "2016-10-09",
          "key": 1476002304000,
          "doc_count": 0
        },
        {
          "key_as_string": "2016-10-17",
          "key": 1476679680000,
          "doc_count": 0
        },
        {
          "key_as_string": "2016-10-25",
          "key": 1477357056000,
          "doc_count": 0
        },
        {
          "key_as_string": "2016-11-01",
          "key": 1478034432000,
          "doc_count": 0
        },
        {
          "key_as_string": "2016-11-09",
          "key": 1478711808000,
          "doc_count": 0
        },
        {
          "key_as_string": "2016-11-17",
          "key": 1479389184000,
          "doc_count": 0
        },
        {
          "key_as_string": "2016-11-25",
          "key": 1480066560000,
          "doc_count": 0
        },
        {
          "key_as_string": "2016-12-03",
          "key": 1480743936000,
          "doc_count": 0
        },
        {
          "key_as_string": "2016-12-11",
          "key": 1481421312000,
          "doc_count": 0
        },
        {
          "key_as_string": "2016-12-18",
          "key": 1482098688000,
          "doc_count": 0
        },
        {
          "key_as_string": "2016-12-26",
          "key": 1482776064000,
          "doc_count": 0
        },
        {
          "key_as_string": "2017-01-03",
          "key": 1483453440000,
          "doc_count": 0
        },
        {
          "key_as_string": "2017-01-11",
          "key": 1484130816000,
          "doc_count": 0
        },
        {
          "key_as_string": "2017-01-19",
          "key": 1484808192000,
          "doc_count": 0
        },
        {
          "key_as_string": "2017-01-27",
          "key": 1485485568000,
          "doc_count": 0
        },
        {
          "key_as_string": "2017-02-03",
          "key": 1486162944000,
          "doc_count": 0
        },
        {
          "key_as_string": "2017-02-11",
          "key": 1486840320000,
          "doc_count": 0
        },
        {
          "key_as_string": "2017-02-19",
          "key": 1487517696000,
          "doc_count": 0
        },
        {
          "key_as_string": "2017-02-27",
          "key": 1488195072000,
          "doc_count": 0
        },
        {
          "key_as_string": "2017-03-07",
          "key": 1488872448000,
          "doc_count": 0
        },
        {
          "key_as_string": "2017-03-15",
          "key": 1489549824000,
          "doc_count": 0
        },
        {
          "key_as_string": "2017-03-23",
          "key": 1490227200000,
          "doc_count": 0
        },
        {
          "key_as_string": "2017-03-30",
          "key": 1490904576000,
          "doc_count": 0
        },
        {
          "key_as_string": "2017-04-07",
          "key": 1491581952000,
          "doc_count": 0
        }
      ]
    }
  }
}

First bucket should be 2016-09-01

Please format your code, logs or configuration files using </> icon as explained in this guide and not the citation button. It will make your post more readable.

Or use markdown style like:

```
CODE
```

This is the icon to use if you are not using markdown format:

There's a live preview panel for exactly this reasons.

Lots of people read these forums, and many of them will simply skip over a post that is difficult to read, because it's just too large an investment of their time to try and follow a wall of badly formatted text.
If your goal is to get an answer to your questions, it's in your interest to make it as easy to read and understand as possible.
Please update your post.

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