ElasticSearch索引unix时间戳 [英] ElasticSearch index unix timestamp
问题描述
我必须索引包含'time'字段的文档,其值是一个整数,表示从历元(也称为unix时间戳)开始的秒数。
I have to index documents containing a 'time' field whose value is an integer representing the number of seconds since epoch (aka unix timestamp).
一直在阅读ES文档,并发现这一点:
I've been reading ES docs and have found this:
http://www.elasticsearch.org/guide/reference/mapping/date-format.html
但是,如果我想提交unix时间戳,并希望它们存储在date字段中(整数字段对我来说无用)我只有两个选项:
But it seems that if I want to submit unix timestamps and want them stored in a 'date' field (integer field is not useful for me) I have only two options:
- 实现自己的日期格式
- 在发件人转换为支持的格式
有没有其他选项我错过了?
Is there any other option I missed?
谢谢!
推荐答案
告诉ES字段的映射是一个日期,它可以使用时代毫秒作为输入。如果您希望ES自动检测,您将必须提供ISO8601或其他可发现的格式。
If you supply a mapping that tells ES the field is a date, it can use epoch millis as an input. If you want ES to auto-detect you'll have to provide ISO8601 or other discoverable format.
更新:我还应该注意,您可以影响ES将会识别哪些字符串作为映射中的日期。 http://www.elastic.co/guide/en/elasticsearch/ reference / current / mapping-date-format.html
Update: I should also note that you can influence what strings ES will recognize as dates in your mapping. http://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-date-format.html
这篇关于ElasticSearch索引unix时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!