elasticsearch使用river同步mysql数据
====== 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
curl -XDELETE 'localhost:9200/_river/report_jdbc_river'
elasticsearch使用river同步mysql数据的更多相关文章
- 推荐一个同步Mysql数据到Elasticsearch的工具
把Mysql的数据同步到Elasticsearch是个很常见的需求,但在Github里找到的同步工具用起来或多或少都有些别扭. 例如:某记录内容为"aaa|bbb|ccc",将其按 ...
- centos7配置Logstash同步Mysql数据到Elasticsearch
Logstash 是开源的服务器端数据处理管道,能够同时从多个来源采集数据,转换数据,然后将数据发送到您最喜欢的“存储库”中.个人认为这款插件是比较稳定,容易配置的使用Logstash之前,我们得明确 ...
- 使用Logstash来实时同步MySQL数据到ES
上篇讲到了ES和Head插件的环境搭建和配置,也简单模拟了数据作测试 本篇我们来实战从MYSQL里直接同步数据 一.首先下载和你的ES对应的logstash版本,本篇我们使用的都是6.1.1 下载后使 ...
- 使用logstash同步MySQL数据到ES
使用logstash同步MySQL数据到ES 版权声明:[分享也是一种提高]个人转载请在正文开头明显位置注明出处,未经作者同意禁止企业/组织转载,禁止私自更改原文,禁止用于商业目的. https:// ...
- Logstash使用jdbc_input同步Mysql数据时遇到的空时间SQLException问题
今天在使用Logstash的jdbc_input插件同步Mysql数据时,本来应该能搜索出10条数据,结果在Elasticsearch中只看到了4条,终端中只给出了如下信息 [2017-08-25T1 ...
- ElasticSearch 安装 go-mysql-elasticsearch 同步mysql的数据
一.首先在Centos6.5上安装 go 语言环境 下载Golang语言包:https://studygolang.com/dl [hoojjack@localhost src]$ ls apache ...
- 实战ELK(6)使用logstash同步mysql数据到ElasticSearch
一.准备 1.mysql 我这里准备了个数据库mysqlEs,表User 结构如下 添加几条记录 2.创建elasticsearch索引 curl -XPUT 'localhost:9200/user ...
- 同步mysql数据到ElasticSearch的最佳实践
Elasticsearch是一个实时的分布式搜索和分析引擎.它可以帮助你用前所未有的速度去处理大规模数据.ElasticSearch是一个基于Lucene的搜索服务器.它提供了一个分布式多用户能力的全 ...
- 【记录】ELK之logstash同步mysql数据到Elasticsearch ,配置文件详解
本文出处:https://my.oschina.net/xiaowangqiongyou/blog/1812708#comments 截取部分内容以便学习 input { jdbc { # mysql ...
随机推荐
- [傻瓜版] Redis在Windows下的开发环境配置步骤
redis默认运行在unix体系下,windows无法直接运行官方版.以下是几种解决方案, 一)Windows移植版.启动速度飞快,优先推荐使用. a) 2.6.12 是稳定版,我用64位版来做开发环 ...
- .Net程序员学用Oracle系列(17):数据库管理工具(SQL Plus)
1.数据库管理工具概述 2.SQL Plus 实用命令参考 2.1.连接/断开命令 2.2.执行 SQL 语句 2.3.执行 PL/SQL 语句 2.4.文件操作命令 2.5.修改用户密码 2.6.执 ...
- margin-top、margin-bottom的一些分析
margin-top:表示该容器距离上面容器的距离 情况一:如果该容器上面没有容器,则这个样式属性则被父容器占用了 html代码如下: <div id ="fa"> & ...
- 解决Ubuntu不能连接xshell
首先,判断Ubuntu是否安装了ssh服务: 1.ps -e |grep ssh 如果服务已经启动,则可以同时看到“ssh-agent”和“sshd”,否则表示没有安装服务,或没有开机启动 2.安装s ...
- c++针对数据库,文件的操作总结(原始)
1.将文件保存到sqlserver数据库的相关操作: Update t1 .txt’, SINGLE_BLOB ) Select convert( varchar(), data ) 注:fileTy ...
- 一次MySQL死锁问题解决
一次MySQL死锁问题解决 一.环境 CentOS, MySQL 5.6.21-70, JPA 问题场景:系统有定时批量更新数据状态操作,每次更新上千条记录,表中总记录数约为500W左右. 二.错误日 ...
- Linux 压缩解压及备份命令
linux中压缩与备份命令总结一.压缩与解压缩 1.compress [-rcv] 文件或目录 <==压缩 uncompress 文件.Z <==解压缩 -r:可以连同目录下的文件也同时进 ...
- TypeScript 优秀开源项目大合集
TypeScript出来有段时间了,也冒出了很多用TypeScript开发的优秀开源项目,搜寻了一些基于TypeScript项目,分享给大家: https://github.com/brookshi/ ...
- TP框架 基础1
php框架 一.真实项目开发步骤: 多人同时开发项目,协作开发项目.分工合理.效率有提高(代码风格不一样.分工不好) 测试阶段 上线运行 对项目进行维护.修改.升级(单个人维护项目,十分困难,代码风格 ...
- Convert Sorted Array to Binary Search Tree & Convert Sorted List to Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST. Su ...