0
点赞
收藏
分享

微信扫一扫

logstash中同步mysql到elastic常见问题总结

_karen 2022-11-21 阅读 40

1. mysql查询字段中有 type字段

问题原因

select语句中查到了type, 但es中会默认有一个type, 这使得两个type冲突.会导致同步失败,且没有报错


GET my_index/_mapping 返回的数据中包含一个type字段如下: "type" : {           "type" : "text",           "fields" : {             "keyword" : {               "type" : "keyword",               "ignore_above" : 256           }       } }


解决办法
去掉type或者改名为其它字段table_type即可, 问题解决

 

2.当配置了保存最后更新记录的情况下,直接删除不能重新同步


record_last_run => true last_run_metadata_path => "/usr/local/logstash/config/run/ru n_last_record_id"


当配置是上面这种情况时,如果直接删掉/usr/local/logstash/config/run/run_last_record_id是无法直接重新同步的,还是需要重启下

 

3.logstash向es中导入mysql数据,tinyint字段导入过程中抛出mapper_parsing_exception类型异常

场景:

使用logstash向elasticsearch导入mysql数据,有一个is_top的字段,数据库类型为tinyint(1),在logstash导入过程中,报错

错误信息为:


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_top": {         "type": "long"     } }


解决方案:

mysql的导出Jar会默认将tinyint(1)转换为boolean,0则为false,大于0则为true。
解决方法是 将tinyint(1)数据库改为tinyint(2),tinyint(2)就会默认转成数字,es的mapping用long接受即可。
 另:如果无法改动数据库字段,我查看其它帖子,说是查询时将tinyint(1)字段乘以1后,再作为结果输出

 

举报

相关推荐

0 条评论