文章目录
- ElasticSearch数据同步
- [1. 同步调用](#1. 同步调用)
- [2. 异步通知](#2. 异步通知)
- [3. 监听binlog](#3. 监听binlog)
- [4. 工作中处理同步的问题](#4. 工作中处理同步的问题)
ElasticSearch数据同步
ElasticSearch中酒店数据来自于mysql数据库,因此MySQL数据发生改变时,ElasticSearch也必须跟着改变,这个就是ElasticSearch和MySQL之间的数据同步

1. 同步调用

- 优点:实现简单粗暴
- 缺点:业务耦合度高
2. 异步通知

- 优点:低耦合,实现难度一般
- 缺点:依赖MQ的可靠性
3. 监听binlog

- 优点:完全解除服务间耦合
- 缺点:开启binlog增加数据库负担,实现复杂度高
4. 工作中处理同步的问题
以上3种,同步调用,异步通知,监听binlog都是增量的 。工作中有时候需要全量刷新ES索引,用过以下几种实现方式:
- 通过Java代码从数据库写到ElasticSearch和定时任务来实现
- 通过Kettle从数据库写到ElasticSearch来实现
- 通过Streamsets从数据库写到ElasticSearch来实现(Streamsets也可以实现监听binlog方式)
- 通过Apache NIFI从数据库写到ElasticSearch来实现
- 通过ESB从数据库写到ElasticSearch来实现