27 |
28 | | Mysql字段类型 |
29 | Elasticsearch类型 |
30 |
31 |
32 | | char |
33 | {"type": "text", "fields": {"keyword": {"type": "keyword", "ignore_above": 256}} |
34 |
35 |
36 | | text |
37 | {"type": "text", "fields": {"keyword": {"type": "keyword", "ignore_above": 256}} |
38 |
39 |
40 | | blob |
41 | {"type": "text", "fields": {"keyword": {"type": "keyword", "ignore_above": 256}} |
42 |
43 |
44 | | int |
45 | {"type": "long"} |
46 |
47 |
48 | | date |
49 | {"type": "date"} |
50 |
51 |
52 | | time |
53 | {"type": "date"} |
54 |
55 |
56 | | float |
57 | {"type": "float"} |
58 |
59 |
60 | | double |
61 | {"type": "float"} |
62 |
63 |
64 | | decimal |
65 | {"type": "float"} |
66 |
67 |
68 | | 其它 |
69 | {"type": "text", "fields": {"keyword": {"type": "keyword", "ignore_above": 256}} |
70 |
71 |
72 |
73 | ## 注意事项
74 | - Mysql的binlog格式必须为**ROW**
75 | - 因为有行锁,Mysql中table使用的存储引擎须为**InnoDB**
76 | - 由于使用binlog进行增量同步,和数据库主从类似,不可避免的会有一定的主从延迟,延迟时间取决于机房网络、机器负载、数据量大小等
77 | - Elasticsearch支持的版本为**5.x**
78 | - canal已测试版为**v1.0.24**,其他版本请自行测试
79 | - 增量同步只监听了 **INSERT、UPDATE、DELETE**,其它如建表、删表等尚未支持
80 | - 建议Elasticsearch的mapping手动来创建,因为默认的创建方式不能保证满足业务需求
81 |
82 | ## 相关文档
83 | - [wiki](https://github.com/starcwang/canal_mysql_elasticsearch_sync/wiki)
84 | - [HttpApi](https://github.com/starcwang/canal_mysql_elasticsearch_sync/wiki/HttpApi)
85 | - [QuickStart](https://github.com/starcwang/canal_mysql_elasticsearch_sync/wiki/QuickStart)
86 |
87 | ## 联系方式
88 | 如果有不合理的地方,还请不吝赐教。
89 | - QQ群:733688083
90 |
91 | **支持记得star✨**
92 |
--------------------------------------------------------------------------------
/src/main/java/com/star/sync/elasticsearch/listener/AbstractCanalListener.java:
--------------------------------------------------------------------------------
1 | package com.star.sync.elasticsearch.listener;
2 |
3 | import com.alibaba.otter.canal.protocol.CanalEntry.Column;
4 | import com.alibaba.otter.canal.protocol.CanalEntry.Entry;
5 | import com.alibaba.otter.canal.protocol.CanalEntry.RowChange;
6 | import com.alibaba.otter.canal.protocol.CanalEntry.RowData;
7 | import com.google.protobuf.InvalidProtocolBufferException;
8 | import com.star.sync.elasticsearch.event.AbstractCanalEvent;
9 | import com.star.sync.elasticsearch.model.DatabaseTableModel;
10 | import com.star.sync.elasticsearch.model.IndexTypeModel;
11 | import com.star.sync.elasticsearch.service.MappingService;
12 | import org.slf4j.Logger;
13 | import org.slf4j.LoggerFactory;
14 | import org.springframework.context.ApplicationListener;
15 |
16 | import javax.annotation.Resource;
17 | import java.util.HashMap;
18 | import java.util.List;
19 | import java.util.Map;
20 |
21 | /**
22 | * @author