elasticsearch使用river同步mysql数据
来源:互联网 发布:詹姆斯总决赛数据科比 编辑:程序博客网 时间:2024/05/18 10:52
====== mysql的river介绍======
- 什么是river?river代表es的一个数据源,也是其它存储方式(如:数据库)同步数据到es的一个方法。它是以插件方式存在的一个es服务,通过读取river中的数据并把它索引到es中,官方的river有couchDB的,RabbitMQ的,Twitter的,Wikipedia的。这里主要研究针对mysql的river。
- mysql的river插件:mysql的river安装见https://github.com/jprante/elasticsearch-river-jdbc,就不具体介绍了。
- 实践测试:
* 环境:
服务器172.16.170.21 数据库:profile 表user
* 创建索引
curl -XPUT 'http://localhost:9200/profile'
* 创建数据表与索引映射
curl -XPUT 'http://localhost:9200/profile/user/_mapping' -d '
{
"user": {
"properties": {
"id": {
"type": "string",
"store": "yes"
},
"name": {
"type": "string",
"store": "yes"
},
"login_name": {
"type": "string",
"store": "yes"
}
}
}
}'
* 运行river同步数据
curl -XPUT 'http://localhost:9200/_river/who_jdbc_river/_meta' -d '{
"type": "jdbc",
"jdbc": {
"driver": "com.mysql.jdbc.Driver",
"url": "jdbc:mysql://localhost:3306/profile",
"user": "root",
"password": "root",
"sql": "select id as _id,name,login_name from user",
"index": "profile",
"type": "user",
"bulk_size": 100,
"max_bulk_requests": 30,
"bulk_timeout": "10s",
"flush_interval": "5s",
"schedule": "0 0-59 0-23 ? * *"
}
}'
* 增量更新索引
增量更新,表需要维护时间戳,发现时间戳更新的列需要更新
curl -XPUT 'http://localhost:9200/_river/who_jdbc_river/_meta' -d '{
"type": "jdbc",
"jdbc": {
"driver": "com.mysql.jdbc.Driver",
"url": "jdbc:mysql://localhost:3306/profile",
"user": "root",
"password": "root",
"sql": [
{
"statement": "select id as _id,name,login_name from user where mytimestamp > ?",
"parameter": [
"$river.state.last_active_begin"
]
}
],
"index": "profile",
"type": "user",
"bulk_size": 100,
"max_bulk_requests": 30,
"bulk_timeout": "10s",
"flush_interval": "5s",
"schedule": "0 0-59 0-23 ? * *"
}
}'
- 什么是river?river代表es的一个数据源,也是其它存储方式(如:数据库)同步数据到es的一个方法。它是以插件方式存在的一个es服务,通过读取river中的数据并把它索引到es中,官方的river有couchDB的,RabbitMQ的,Twitter的,Wikipedia的。这里主要研究针对mysql的river。
- mysql的river插件:mysql的river安装见https://github.com/jprante/elasticsearch-river-jdbc,就不具体介绍了。
- 实践测试:
* 环境:
服务器172.16.170.21 数据库:profile 表user
* 创建索引
curl -XPUT 'http://localhost:9200/profile'
* 创建数据表与索引映射
curl -XPUT 'http://localhost:9200/profile/user/_mapping' -d '
{
"user": {
"properties": {
"id": {
"type": "string",
"store": "yes"
},
"name": {
"type": "string",
"store": "yes"
},
"login_name": {
"type": "string",
"store": "yes"
}
}
}
}'
* 运行river同步数据
curl -XPUT 'http://localhost:9200/_river/who_jdbc_river/_meta' -d '{
"type": "jdbc",
"jdbc": {
"driver": "com.mysql.jdbc.Driver",
"url": "jdbc:mysql://localhost:3306/profile",
"user": "root",
"password": "root",
"sql": "select id as _id,name,login_name from user",
"index": "profile",
"type": "user",
"bulk_size": 100,
"max_bulk_requests": 30,
"bulk_timeout": "10s",
"flush_interval": "5s",
"schedule": "0 0-59 0-23 ? * *"
}
}'
* 增量更新索引
增量更新,表需要维护时间戳,发现时间戳更新的列需要更新
curl -XPUT 'http://localhost:9200/_river/who_jdbc_river/_meta' -d '{
"type": "jdbc",
"jdbc": {
"driver": "com.mysql.jdbc.Driver",
"url": "jdbc:mysql://localhost:3306/profile",
"user": "root",
"password": "root",
"sql": [
{
"statement": "select id as _id,name,login_name from user where mytimestamp > ?",
"parameter": [
"$river.state.last_active_begin"
]
}
],
"index": "profile",
"type": "user",
"bulk_size": 100,
"max_bulk_requests": 30,
"bulk_timeout": "10s",
"flush_interval": "5s",
"schedule": "0 0-59 0-23 ? * *"
}
}'
删除river
curl -XDELETE 'localhost:9200/_river/report_jdbc_river'
0 0
- elasticsearch使用river同步mysql数据
- elasticsearch使用river同步mysql数据
- 用elasticsearch-river-jdbc同步数据到elasticsearch
- 用elasticsearch-river-jdbc同步数据到elasticsearch
- 关于Elasticsearch使用jdbc-river同步数据每次追加的问题
- Elasticsearch+mysql 数据同步
- elasticsearch mysql数据同步
- 单机搭建elasticsearch和mongodb river的数据同步
- Elasticsearch+MySQL数据同步示例
- mysql中的数据同步到elasticsearch
- 搭建elasticsearch,并同步mysql数据
- 实时同步MySQL数据到Elasticsearch
- Elasticsearch学习笔记(二) mysql数据同步
- ElasticSearch同步MySql
- 同步mysql数据到ElasticSearch的最佳实践
- 同步mysql数据到ElasticSearch的最佳实践
- Elasticsearch安装及自动同步mysql数据库数据
- 用python简单实现mysql数据同步到ElasticSearch
- 程序员的走与留?
- MPAndroidChart添加自定义样式
- 关于匿名内部类的问题
- aliyun阿里云Maven仓库镜像地址
- 拓扑排序学习笔记-Java
- elasticsearch使用river同步mysql数据
- 封装一个函数afterDate(date,n),得到日期date的n天后的日期
- Ubuntu 14.04下Redis安装报错:“You need tcl 8.5 or newer in order to run the Redis test”问题解决
- 计算机导论2--语言与算法
- READING NOTE: Weakly Supervised Cascaded Convolutional Networks
- 堆排序
- 未越狱iPhone访问限制密码忘了怎么办
- maven打包pom文件在windows和linux下的格式差异
- C#63课的主要内容