同步数据库到elasticsearch

elasticsearch-jdbc同步数据库到elasticsearch

一、elasticsearch-jdbc的介绍
同步数据库到elasticSearch的插件elasticsearch-jdbc
之前的名称是elasticsearch-river-jdbc

下载地址:
http://xbib.org/repository/org/xbib/elasticsearch/importer/elasticsearch-jdbc//elasticsearch-jdbc--dist.zip
下载时将替换成相应的版本即可。
如:
http://xbib.org/repository/org/xbib/elasticsearch/importer/elasticsearch-jdbc/2.3.2.0/elasticsearch-jdbc-2.3.2.0-dist.zip

附:源码地址
https://github.com/jprante/elasticsearch-jdbc

二、elasticsearch-jdbc的使用
这里只介绍使用elasticsearch-jdbc同步mssql数据到elasticsearch中

1.创建索引
curl -XPUT ‘http://localhost:9200/baikeDb

2.创建数据表与索引映射

curl -XPUT 'http://localhost:9200/baikeDb/user/_mapping' -d '
{
    "user": {
        "properties": {
            "id": {
                "type": "string",
                "store": "yes"
            },
            "name": {
                "type": "string",
                "store": "yes"
            },
            "login_name": {
                "type": "string",
                "store": "yes"
            }
        }
    }
}'

3.运行river同步数据

curl -XPUT 'http://localhost:9200/baikeDb/_meta' -d '{
    "type": "jdbc",
    "jdbc": {
        "url": "jdbc:sqlserver://localhost:1433;databaseName=baikeDb",
        "user": "sa",
        "password": "123456",
        "sql": "select id as _id,name,login_name from user",
        "index": "baikeDb",
        "type": "user",
        "bulk_size": 100,
        "max_bulk_requests": 30,
        "bulk_timeout": "10s",
        "flush_interval": "5s",
        "schedule": "0 0-59 0-23 ? * *"
    }
}'

4.增量更新索引
增量更新,表需要维护时间戳,发现时间戳更新的列需要更新

curl -XPUT 'http://localhost:9200/baikeDb/_meta' -d '{
    "type": "jdbc",
    "jdbc": {
        "url": "jdbc:sqlserver://localhost:1433;databaseName=baikeDb",
        "user": "sa",
        "password": "123456",
        "sql": [
            {
                "statement": "select id as _id,name,login_name from user where mytimestamp > ?",
                "parameter": [
                    "$river.state.last_active_begin"
                ]
            }
        ],
        "index": "baikeDb",
        "type": "user",
        "bulk_size": 100,
        "max_bulk_requests": 30,
        "bulk_timeout": "10s",
        "flush_interval": "5s",
        "schedule": "0 0-59 0-23 ? * *"
    }
}'

5.删除索引

curl -XDELETE ‘localhost:9200/baikeDb’

参考:
http://blog.csdn.net/kingice1014/article/details/53492773

  • 4
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值