elasticsearch使用river同步mysql数据
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了elasticsearch使用river同步mysql数据,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2629字,纯文字阅读大概需要4分钟。
内容图文
![elasticsearch使用river同步mysql数据](/upload/InfoBanner/zyjiaocheng/477/e5af5fd537d045178a8d435bfacc1c75.jpg)
- 什么是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‘
elasticsearch使用river同步mysql数据
标签:use file log nbsp 个数 安装 ros put select
本文系统来源:http://www.cnblogs.com/zfblog/p/6537162.html
内容总结
以上是互联网集市为您收集整理的elasticsearch使用river同步mysql数据全部内容,希望文章能够帮你解决elasticsearch使用river同步mysql数据所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。