elasticsearch 实时性这个可以实时的从mysql数据源中更新数据吗

2160人阅读
【Elasticsearch 检索技术】(22)
go-mysql-elasticsearch 是国内作者开发的一款插件。测试表明:该插件优点:能实现同步增、删、改、查操作。不足之处(待完善的地方):
1、仍处理开发、相对不稳定阶段;
2、没有日志,不便于排查问题及查看同步结果。
本文深入详解了插件的安装、使用、增删改查同步测试。
步骤1:安装go
yum install go
步骤2:安装godep
go /tools/godep
go /siddontang/go-mysql-elasticsearch
cd $GOPATH//siddontang/go-mysql-elasticsearch
2.1修改配置文件
[root@5b9dbaaa148a etc]# cat river.toml
# MySQL address, user and password
# user must have replication privilege in MySQL.
my_addr = "192.168.1.1:3306"
my_user = "root"
my_pass = "password@!"
# Elasticsearch address
es_addr = "192.168.1.1:9200"
# Path to store data, , and dump MySQL data
data_dir = "./var"
# Inner Http status address
stat_addr = "192.168.1.1:12800"
# pseudo server id like a slave
server_id = 1
# mysql or mariadb
flavor = "mysql"
# mysqldump execution path
mysqldump = "mysqldump"
# MySQL data source
[[source]]
schema = "test"
# Only below tables will be synced into Elasticsearch.
# "test_river_[0-9]{4}" is a wildcard table format, you can use it if you have many sub tables, like table_0000 - table_1023
# I don't think it is necessary to sync all tables in a database.
tables = ["cc"]
# Below is for special rule mapping
#schema = "test"
#table = "cc"
#index = "go_river"
#type = "go_rivert"
# title is MySQL test_river field name, es_title is the customized name in Elasticsearch
[rule.field]
# This will map column title to elastic search my_title
title="es_title"
# This will map column tags to elastic search my_tags and use array type
# tags="my_tags,list"
# This will map column keywords to elastic search keywords and use array type
#keywords=",list"
# wildcard table rule, the wildcard table must be in source tables
schema = "test"
table = "cc"
index = "gocc"
type = "gocc_t"
# title is MySQL test_river field name, es_title is the customized name in Elasticsearch
[[rule.fields]]
mysql = "mysql101"
elastic = "es_mysql101"
2.2执行同步操作
cd $GOPATH//siddontang/go-mysql-elasticsearch
./bin/go-mysql-elasticsearch -config=./etc/river.toml
3.1插入Insert操作实时同步验证(验证ok)
3.1.1Mysql端插入操作
mysql& insert into cc(id,name) values(12, ‘test12’);
Query OK, 1 row affected (0.06 sec)
3.1.2Mysql执行insert后查询结果
mysql& select * from cc where id =12;
+—-+——–+——–+———————+
| id | name
| status | modified_at
+—-+——–+——–+———————+
| 12 | test12 | ok
02:27:29 |
+—-+——–+——–+———————+
1 row in set (0.02 sec)
3.1.3ES端能查询到新增的value字段。
[root@5b9dbaaa148a bin]# curl -XGET http:
& {"query":
& {"term":
& {"id":12}}}'
"took" : 402,
"timed_out" : false,
"_shards" : {
"total" : 8,
"successful" : 8,
"failed" : 0
"hits" : {
"total" : 1,
"max_score" : 1.0,
"hits" : [ {
"_index" : "gocc",
"_type" : "gocc_t",
"_id" : "12",
"_score" : 1.0,
"_source" : {
"id" : 12,
"modified_at" : "T02:27:29+01:00",
"name" : "test12",
"status" : "ok"
3.2.1mysql执行更新操作
mysql& update cc set name = 'test12_001' where id = 12;
Query OK, 1 row affected (0.05 sec)
Rows matched: 1
Changed: 1
Warnings: 0
3.2.2mysql执行修改后查询
Mysql查询修改后结果:
1 row in set (0.00 sec)
3.2.3 ES查询修改结果
[root@5b9dbaaa148a bin]# curl -XGET http:
{"id":12}}}'
"took" : 59,
"timed_out" : false,
"_shards" : {
"total" : 8,
"successful" : 8,
"failed" : 0
"hits" : {
"total" : 1,
"max_score" : 1.0,
"hits" : [ {
"_index" : "gocc",
"_type" : "gocc_t",
"_id" : "12",
"_score" : 1.0,
"_source" : {
"id" : 12,
"modified_at" : "T02:27:29+01:00",
"name" : "test12_001",
"status" : "ok"
3.3删除操作实时同步验证
3.3.1Mysql执行删除操作
mysql& delete from cc where id = 12;
Query OK, 1 row affected (0.04 sec)
3.3.2删除后查询表
mysql& select *
+----+--------------------+--------+---------------------+
| id | name
| status | modified_at
+----+--------------------+--------+---------------------+
1 | laoyang360
| 0000-00-00 00:00:00 |
2 | test002
| 2016-06-23 06:16:42 |
3 | dlllaoyang360
| 0000-00-00 00:00:00 |
| 11 | test11
| 2016-06-24 02:09:15 |
5 | jdbc_test_update08 | ok
| 0000-00-00 00:00:00 |
| 0000-00-00 00:00:00 |
8 | test008
| 0000-00-00 00:00:00 |
9 | test009
| 0000-00-00 00:00:00 |
| 10 | test10
| 2016-06-24 02:08:14 |
+----+--------------------+--------+---------------------+
9 rows in set (0.02 sec)
3.3.3ES查询删除后结果
[root@5b9dbaaa148a bin]# curl -XGET http:
{"id":12}}}'
"took" : 40,
"timed_out" : false,
"_shards" : {
"total" : 8,
"successful" : 8,
"failed" : 0
"hits" : {
"total" : 0,
"max_score" : null,
"hits" : [ ]
验证发现:
(1)go-mysql-elasticsearch插件可以实现同步insert、update、delete操作。
(2)可视化做的不好,没有打印日志。
(3)go-mysql-elasticsearch尚不大稳定,出现过无法同步成功的情况,但没有报错。不便于排查。
作者:铭毅天下
转载请标明出处,原文地址:
如果感觉本文对您有帮助,请点击‘顶’支持一下,您的支持是我坚持写作最大的动力,谢谢!
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:569663次
积分:8375
积分:8375
排名:第1601名
原创:197篇
转载:29篇
评论:528条
文章:24篇
阅读:57314
(12)(6)(8)(10)(5)(7)(2)(1)(4)(3)(1)(1)(3)(3)(4)(2)(2)(1)(1)(9)(3)(2)(1)(1)(1)(1)(1)(1)(2)(1)(1)(3)(2)(7)(1)(2)(3)(1)(2)(1)(3)(6)(2)(5)(6)(8)(15)(13)(13)(13)(1)(12)(3)(5)16:28 提问
Elastic Search 与 mysql数据库实时同步的问题
我知道有一个工具叫ElasticSearch-jdbc,也看了官方文档,根据官方文档写了个测试(命令见最下),但是不能实时同步,它会隔差不多1分钟左右再更新。不知道是什么地方出问题了。还请路过大神不吝赐教!
"type" : "jdbc",
"jdbc" : {
"url" : "jdbc:mysql://xxx.xxx.xxx.xxx:3306/world",
"user" : "root",
"password" : "xxxxxx",
"schedule":"*/5 * * * * ?",
"locale" : "en_US",
"statement":"select \"world\" as _index, \"city\" as _type, ID as _id, Name as \"Name\", CountryCode as \"CountryCode\", District as \"District\", Population as \"Population\" from city where
\"mytimestamp\" & ?",
"parameter":
[ "$metrics.lastexecutionstart" ]
"statement" : "delete from city where \"_job\" = ?",
"parameter" : [ "$job" ]
"statefile":"statefile.json",
"elasticsearch" : {
"cluster" : "my_cluster_name1",
"host" : "localhost",
"port" : 9300
"index" : "world",
"type" : "city",
"index_settings" : {
"index" : {
"number_of_shards" : 1
731关注|675收录
603关注|105收录
389关注|632收录
其他相似问题ElasticSearch这个可以实时的从mysql数据源中更新数据吗_百度知道问题对人有帮助,内容完整,我也想知道答案
问题没有实际价值,缺少关键内容,没有改进余地
ElasticSearch这个可以实时的从mysql数据源中更新数据吗?
网络找了些资料都是介绍建索引,搜索之类.对于数据源的更新介绍的不多.有没有文档专门介绍或者教程什么的?
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
分享到微博?
你好!看起来你挺喜欢这个内容,但是你还没有注册帐号。 当你创建了帐号,我们能准确地追踪你关注的问题,在有新答案或内容的时候收到网页和邮件通知。还能直接向作者咨询更多细节。如果上面的内容有帮助,记得点赞 (????)? 表示感谢。
明天提醒我
关闭理由:
删除理由:
忽略理由:
推广(招聘、广告、SEO 等)方面的内容
与已有问题重复(请编辑该提问指向已有相同问题)
答非所问,不符合答题要求
宜作评论而非答案
带有人身攻击、辱骂、仇恨等违反条款的内容
无法获得确切结果的问题
非开发直接相关的问题
非技术提问的讨论型问题
其他原因(请补充说明)
我要该,理由是:
扫扫下载 App
SegmentFault
一起探索更多未知

我要回帖

更多关于 elasticsearch和mysql 的文章

 

随机推荐