python - ElasticSearch日期格式,支持小数秒

标签 python datetime elasticsearch datetime-format

我试图将日期时间映射插入支持小数秒格式符号的ElasticSearch中。

我的Json Documents中的Timestamp值的示例是:
2019-09-03T19:55:01.8127303Z
因此,要将这些值映射到索引中,我使用了以下日期格式:

custom_date_format = "yyyy-MM-dd'T'HH:mm:ss.SSSSSSSZ";
"properties" : {
"Timestamp": {  
                    "type":   "date",
                    "format": custom_date_format
            },
#(...etc...)
}

当我使用此映射插入文档时,出现错误:
{"type":"illegal_argument_exception",
"reason":"failed to parse date field [2019-09-03T18:51:45.7506712Z] with format [yyyy-MM-dd\'T\'HH:mm:ss.SSSSSSSZ]",
"caused_by":{"type":"date_time_parse_exception",
"reason":"Text \'2019-09-03T18:51:45.7506712Z\' could not be parsed at index 27"}}}

我没有看到日期格式的错误,只是在ElasticSearch文档上没有这种类型的日期时间的示例。

两个问题:
  • 可以使用这种格式来解析此类型的日期时间吗?
  • 解析它们时是否可以完全跳过小数秒的最后7位?它们不是必需的,但是在我获得的原始文档中,它们是如何提供的。
  • 最佳答案

    Elastic Search中的日期格式一开始是不可能的。使它们工作的唯一方法是使用Java方法,而不是Python。

    我将这些转换为基于整数的Unix时间值,或者在对这些文档进行范围查询时进行原始全文查询。

    关于python - ElasticSearch日期格式,支持小数秒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57811426/

    相关文章:

    python - 检查 ipython 中最后一个命令的退出状态

    python - 创建图像数据的pickeled数据文件

    matlab - 为什么 Matlab 中两个不同格式的日期时间不相等?

    elasticsearch - 在所有父项和子项字段上将Elasticsearch转换为AND

    elasticsearch - ElasticSearch:如何设置到模板的默认映射

    python - 列出 64 位 Windows 上正在运行的进程

    python - 在 Dataframe float32 列上使用 list(zip(...)) 时出现 float 问题

    java - 使用 UCanAccess JDBC 驱动程序时格式化日期

    python - 仅从数据框中选择每个月的最后一周 - Python/Pandas

    elasticsearch - Elasticsearch 索引模板可以为字段定义默认类型,并且仅允许覆盖特定字段吗?