logstash向es中导入mysql数据,tinyint字段导入过程中抛出mapper_parsing_exception类型异常
Logstash | 作者 piggyci | 发布于2017年12月20日 | 阅读数:9406
使用logstash向elasticsearch导入mysql数据,有一个is_sync的字段,数据库类型为tinyint(1),在logstash导入过程中,报错
错误信息为:
[2017-12-20T14:02:56,939][WARN ][logstash.outputs.elasticsearch] Could not index event to Elasticsearch. {:status=>400, :action=>["index", {:_id=>nil, :_index=>"exam", :_type=>"exam", :_routing=>nil}, #<LogStash::Event:0x2a099160>], :response=>{"index"=>{"_index"=>"exam", "_type"=>"exam", "_id"=>"9xSEcmABD-UhuoDsiTy5", "status"=>400, "error"=>{"type"=>"mapper_parsing_exception", "reason"=>"failed to parse [is_sync]", "caused_by"=>{"type"=>"i_o_exception", "reason"=>"Current token (VALUE_FALSE) not numeric, can not use numeric value accessors\n at [Source: org.elasticsearch.common.bytes.BytesReference$MarkSupportingStreamInputWrapper@4ad19246; line: 1, column: 355]"}}}}}
es中的mapping为:
"is_sync": {
"type": "byte"
}
错误信息为:
[2017-12-20T14:02:56,939][WARN ][logstash.outputs.elasticsearch] Could not index event to Elasticsearch. {:status=>400, :action=>["index", {:_id=>nil, :_index=>"exam", :_type=>"exam", :_routing=>nil}, #<LogStash::Event:0x2a099160>], :response=>{"index"=>{"_index"=>"exam", "_type"=>"exam", "_id"=>"9xSEcmABD-UhuoDsiTy5", "status"=>400, "error"=>{"type"=>"mapper_parsing_exception", "reason"=>"failed to parse [is_sync]", "caused_by"=>{"type"=>"i_o_exception", "reason"=>"Current token (VALUE_FALSE) not numeric, can not use numeric value accessors\n at [Source: org.elasticsearch.common.bytes.BytesReference$MarkSupportingStreamInputWrapper@4ad19246; line: 1, column: 355]"}}}}}
es中的mapping为:
"is_sync": {
"type": "byte"
}
3 个回复
piggyci
赞同来自: guotenv
解决方法是 将tinyint(1)数据库改为tinyint(4),tinyint(4)就会默认转成数字,es的mapping用byte接受即可。
另:如果无法改动数据库字段,我查看其它帖子,说是查询时将tinyint(1)字段乘以1后,再作为结果输出,后台mapping使用integer即可(但未亲测,不知)是否可行
laoyang360 - 《一本书讲透Elasticsearch》作者,Elastic认证工程师 [死磕Elasitcsearch]知识星球地址:http://t.cn/RmwM3N9;微信公众号:铭毅天下; 博客:https://elastic.blog.csdn.net
赞同来自:
guotenv
赞同来自: