You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为何5小时间隔的Date Histogram桶起始于凌晨3点?

Date Histogram桶起始时间不符合预期的问题

我发现Date Histogram的使用颇具难度,因此在极简环境中做了测试:创建仅含1条文档的索引,文档的my_date字段值为"2025-04-25T05:29:00.000Z",想要生成间隔为5小时的Date Histogram。

根据Elasticsearch官方文档,桶的key计算方式为:

bucket_key = Math.floor(value / interval) * interval

按此公式计算,我的场景应该是Math.floor(5.48/5)*5,也就是1*5,桶理应起始于凌晨5点,但实际返回的桶起始于凌晨3点,我无法解释这个现象。

有没有人知道原因?如果能提供客户端编程层面的修复计算方法,将不胜感激!


操作详情

搜索请求

POST 'https://URL_HERE:PORT/date_histogram_bug/_search'

{
    "aggregations": {
        "histogram": {
            "date_histogram": {
                "field": "my_date",
                "fixed_interval": "5h"
            }
        }
    },
    "_source": false,
    "size": 0
}

缩短后的响应

{
    "aggregations": {
        "histogram": {
            "buckets": [
                {
                    "key_as_string": "2025-04-25T03:00:00.000Z",
                    "key": 1745550000000,
                    "doc_count": 1
                }
            ]
        }
    }
}

索引创建请求

PUT 'https://URL_HERE:PORT/date_histogram_bug'

{
  "mappings": {
    "properties": {
      "my_date": { "type": "date" }
    }
  }
}

文档添加请求

PUT 'URL_HERE/date_histogram_bug/_create/42'

{
"my_date": "2025-04-25T05:29:00.000Z"
}

内容的提问来源于stack exchange,提问作者Neifen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 08:27:46