Elasticsearch 底层日期存储格式疑问?

2022-12-15 10:19:01 +08:00
 deadlyn

ES 官网说,

若有大佬知晓,还请不吝解释。

以下为官网原话

  • Values for milliseconds-since-the-epoch must be non-negative. Use a formatted date to represent dates before 1970.
  • Internally, dates are converted to UTC (if the time-zone is specified) and stored as a long number representing milliseconds-since-the-epoch.
  • Queries on dates are internally converted to range queries on this long representation, and the result of aggregations and stored fields is converted back to a string depending on the date format that is associated with the field.
  • Dates will always be rendered as strings, even if they were initially supplied as a long in the JSON document.
1898 次点击
所在节点    Elasticsearch
5 条回复
julyclyde
2022-12-15 10:30:50 +08:00
和 1970 相关很有可能是 unix timestamp 吧
lllpla
2022-12-15 10:47:19 +08:00
说的挺清楚吧 1970 年开始的毫秒值。

1970 年 1 月 1 日 0 时 0 分 0 秒是 0 ,再之前的无法表示。
yangyaofei
2022-12-15 11:47:36 +08:00
这个貌似并不是他真的底层实现, 这个只是他的 Mapping 方式.

我曾经试验过, 存入的字符串是一直存储的, 不管是够改动了 Mapping 什么的都不会变, 但是解析的结果可能会有不一样或者不能解析.

可能他内部直接使用的 Lucene 的时间存储, 至于是什么其实不太重要吧, 可以翻源码
deadlyn
2022-12-15 15:55:24 +08:00
@lllpla 是的,官方说的是,内部会将日期转 UTC 并以长整型存储( milliseconds-since-the-epoch ),疑问是:内部转换以时间戳存储,而这个时间戳只能表示 1970 后的日期,那 1970 前的日期内部如何处理存储呢?

Internally, dates are converted to UTC (if the time-zone is specified) and stored as a long number representing milliseconds-since-the-epoch.
deadlyn
2022-12-15 15:56:57 +08:00
@yangyaofei 嗯,就是读到了官方 doc ,感觉有点冲突,没太理解,有点好奇而已

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/902642

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX