这里处理的是date类型 y-m-d h:i:s格式 时间
问题现象:
image.png
{"index"=>{"_index"=>"product", "_type"=>"_doc", "_id"=>"146", "status"=>400, "error"=>{"type"=>"mapper_parsing_exception", "reason"=>"failed to parse field [create_time] of type [date] in document with id '146'. Preview of field's value: '2022-01-25T09:17:01.000Z'", "caused_by"=>{"type"=>"illegal_argument_exception", "reason"=>"failed to parse date field [2022-01-25T09:17:01.000Z] with format [yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis]", "caused_by"=>{"type"=>"date_time_parse_exception", "reason"=>"Failed to parse with all enclosed parsers"}}}}}}
由于数据时间格式问题导致无法将数据传输到es中,es中的索引对应的时间字段也设置了格式,如下
PUT /product
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 0
},
"mappings": {
"properties": {
"create_time": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss"
},
"update_time": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss"
}
}
}
}
问题原因:
在logstash启动配置中关于mysql的配置部分,原先查询数据使用的方法是:
要执行的sql
statement => "select * from product where update_time > date_add(:sql_last_value, INTERVAL 8 HOUR)"
后面对时间字段做了专门的处理
要执行的sql
statement => "select date_format(create_time,'%Y-%m-%d %H:%i:%s') as create_time, date_format(update_time,'%Y-%m-%d %H:%i:%s') as update_time
from product where update_time > date_add(:sql_last_value, INTERVAL 8 HOUR)"
这样子就可以传输到es中了
logstash 将mysql数据导入es的时候删除多余字段,在filter中
filter {
mutate {
remove_field => "@timestamp"
remove_field => "@version"
}
#时区问题需要修正时间
}