gpt4 book ai didi

elasticsearch - Elasticsearch 中的自定义日期格式

转载 作者:行者123 更新时间:2023-12-03 00:03:01 24 4
gpt4 key购买 nike

我正在尝试使用joda-time库格式在Elastic-Search中格式化日期字段。我想实现"Mon Sep 18 17:12:37 IST 2017"的格式。首先,我使用以下代码:

"alarm_timestamp": {
"type": "date",
"format": "EEE MMM d H:m:s zzz YYYY"
}

它不起作用。后来,我阅读了询问 here的问题。因此,我更改了代码:
"alarm_timestamp": {
"type": "date",
"format": "E MMM d H:m:s z Y"
}

在这两种情况下,映射均已成功创建。但是,当我尝试索引数据时,它给了错误。

它给出的错误是:
{
"error": {
"root_cause": [
{
"type": "mapper_parsing_exception",
"reason": "failed to parse [alarm_timestamp]"
}
],
"type": "mapper_parsing_exception",
"reason": "failed to parse [alarm_timestamp]",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "Invalid format: \"Mon Sep 18 17:12:37 IST 2017\" is malformed at \"IST 2017\""
}
},
"status": 400
}

有什么建议么)?

最佳答案

从Elasticsearch documentation中获取format:

Completely customizable date formats are supported. The syntax for these is explained in the Joda docs.



Joda docs说出有关 z的信息:

Zone names: Time zone names ('z') cannot be parsed.



问题在于这些缩写如时区的 IST可能是模棱两可的。

Wikipedia Time Zone页面显示以下内容:

Abbreviations
Time zones are often represented by alphabetic abbreviations such as "EST", "WST", and "CST", but these are not part of the international time and date standard ISO 8601 and their use as sole designator for a time zone is discouraged. Such designations can be ambiguous; for example, "ECT" could be interpreted as "Eastern Caribbean Time" (UTC−4h), "Ecuador Time" (UTC−5h), or "European Central Time" (UTC+1h).



因此,您将看到一些缩写有效,而有些则无效。鼓励不要使用这些缩写。而是使用以下之一:
  • E MMM d H:m:s Z Y和索引作为Mon Sep 18 17:12:37 +02:00 2017
  • E MMM d H:m:s ZZZ Y和索引作为Mon Sep 18 17:12:37 Europe/Istanbul 2017

  • 这是Joda的 Available Time Zones列表。

    关于elasticsearch - Elasticsearch 中的自定义日期格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47348620/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com