国际化时区-ElasticSearch时区处理

Elasticsearch 中,date 类型的数据以 UTC 时间戳存储。查询和聚合时需注意时区转换,建议统一使用 UTC 并在查询时指定时区,以避免时间不一致问题。聚合查询示例展示了按天聚合日期的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

目录

一、存储格式

二、查询统计

三、使用建议

参考资料


一、存储格式

JSON 本身没有date类型,Elasticsearch将设置了时区的date转换为UTC时间,将没有设置时区的date直接设置为UTC时间,以long型时间戳存储。

官网文档《Date datatype文档》内容如下

Date datatype

JSON doesn’t have a date datatype, so dates in Elasticsearch can either be:

  • strings containing formatted dates, e.g. "2015-01-01" or "2015/01/01 12:10:30".
  • a long number representing milliseconds-since-the-epoch.
  • an integer representing seconds-since-the-epoch.

Internally, dates are converted to UTC (if the time-zone is specified) and stored as a long number representing milliseconds-since-the-epoch

二、查询统计

  • date类型查询,将date转换为long型时间戳查询;
  • date类型聚合,返回结果格式化date字符串;
  • ElasticSearch查询、存储,将date类型转换为UTC long型时间戳。
  • 相同格式存储、查询(同是时间戳或同是格式化字符串),查询时间一致;查询
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值