[英]failed to parse date field, tried both date format [yyyy-MM-dd HH:mm:ss,SSS], and timestamp number with locale []
[英]logstash/elasticsearch failed to parse date field tried both date format [dateOptionalTime], and timestamp number with locale
出於某種原因,logstash(1.5 版)無法處理日志,但出現以下異常:
{:timestamp=>"2016-04-26T09:20:12.141000-0400", :message=>"從字段解析日期失敗", :field=>"time", :value=>"2016-04-26T09: 20:03.520-04:00", :exception=>java.lang.IllegalArgumentException: 格式無效:"2016-04-26T09:20:03.520-04:00" 在 "T09:20:03.520-04:00" 格式錯誤", :level=>:warn}
我在 json 中的時間字段是:
"time":"25-04-2016 04:21:06.786"
我的logstash配置是:
filter {
if [type] == "json" {
json {
source => "message"
}
date {
match => [ "time", "dd-MM-yyyy HH:mm:ss", "dd-MM-yyyy HH:mm:ss:SSS", "dd-MM-yyyy HH:mm:ss.SSS", "yyyy-MM-dd HH:mm:ss,SSS" ]
}
}
}
在 Elasticsearch 方面,我看到了這個異常:
未能解析日期字段 [25-04-2016 04:48:14.305],嘗試了日期格式 [dateOptionalTime] 和帶有語言環境 [] java.lang.IllegalArgumentException: 格式無效的時間戳數:“25-04-2016 04: 48:14.305" 在 "16 04:48:14.305" 格式錯誤
我該如何解決這個問題?
我有同樣的問題; Logstash 會很高興地完成它的工作,但是 Elasticsearch 會抱怨同樣的錯誤。 您可以看到 '@timestamp' 是用正確的變量生成的。 關鍵是理解這種錯誤是它說如下的位:
[2020-07-22 12:27:40,814][DEBUG][action.bulk ] [logs-p03] [logstash-2020.07.22][0] failed to execute bulk item (index) index {[logstash-2020.07.22][logs] ... org.elasticsearch.index.mapper.MapperParsingException: failed to parse [shibidp_timestamp]
...
Caused by: org.elasticsearch.index.mapper.MapperParsingException: failed to parse date field [20200722T002739Z], tried both date format [dateOptionalTime], and timestamp number with locale []
...
Caused by: java.lang.IllegalArgumentException: Invalid format: "20200722T002739Z" is malformed at "2739Z"
這表明映射很糟糕......讓我們看看:
GET http://127.0.0.1:9200/logstash-2020.07.22/_mapping
...
"shibidp_severity" : {
"type" : "string",
"index" : "not_analyzed",
"fields" : {
"raw" : {
"type" : "string",
"index" : "not_analyzed",
"ignore_above" : 256
}
}
},
"shibidp_timestamp" : {
"type" : "date",
"format" : "dateOptionalTime"
},
...
我包括 shibidp_severity 只是為了展示大多數(字符串)是如何被映射的。 該模板不包含與 shibidp_timestamp 匹配的任何內容,或任何其他映射為“日期”類型且格式為“dateOptionalTime”的字段
映射到此的字段(查看 GET http://127.0.0.1:9200/logstash-2020.07.22/_mapping )
此行為似乎與動態日期檢測有關
https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic-field-mapping.html
https://www.elastic.co/guide/en/elasticsearch/reference/1.7/mapping-dynamic-mapping.html
在我的例子中,這個動態映射導致了一些競爭條件(遇到的第一個 'shibidp_timestamp' 值通知當天索引的映射。讓我們看看區別:
$ (d="2020.07.18"; curl -s http://127.0.0.1:9200/logstash-$d/_mapping | jq -c '.["logstash-'$d'"].mappings.logs.properties.shibidp_timestamp')
{"fields":{"raw":{"ignore_above":256,"index":"not_analyzed","type":"string"}},"index":"not_analyzed","type":"string"}
$ (d="2020.07.19"; curl -s http://127.0.0.1:9200/logstash-$d/_mapping | jq -c '.["logstash-'$d'"].mappings.logs.properties.shibidp_timestamp')
{"format":"dateOptionalTime","type":"date"}
這顯示了 shibidp_timestamp 在兩個不同的每日索引中的映射。 前者是我們遇到看起來像字符串的東西時得到的; 后者是當它看起來像時間戳時我們得到的東西(但無法解析為時間戳)
您可以采取一些措施來解決這個問題:
您的@timestamp
具有偏移量(timzeone 值),您需要將其添加到您的配置中。 請參閱此鏈接: https : //www.elastic.co/guide/en/logstash/current/plugins-filters-date.html
Z
時區偏移或標識
Z
:時區偏移結構為 HHmm(從祖魯語/UTC 的小時和分鍾偏移量)。 示例:-0700。ZZ
:時區偏移結構為 HH:mm(小時和分鍾偏移之間的冒號)。 示例:-07:00。ZZZ
:時區標識。 示例:美國/洛杉磯。 注意:有效 ID 列在Joda.org 可用時區頁面上。所以你的模式應該看起來很像:
YYYY-MM-dd HH:mm:ss.SSSZ
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.