Elasticsearch river-jdbc used

mysql-table

CREATE TABLE user (
id int(11) NOT NULL AUTO_INCREMENT,
name varchar(200) COLLATE utf8_bin NOT NULL,
login_name varchar(200) COLLATE utf8_bin DEFAULT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;

insert into user values(null, 'hanmei', 'hm');

建立索引

curl -u username:passwd -X PUT http://node01:9200/index_testdb01 -d'
{
  "mappings": {
    "user": {
      "properties": {
        "id": {
          "type": "long"
        },
        "name": {
          "index": "not_analyzed",
          "type": "string"
        },
        "login_name": {
          "index": "not_analyzed",
          "type": "string"
        }
      }
    }
  }
}
'

同步数据

curl -XPUT 'http://localhost:9200/_river/testdb01/_meta' -d '{   ## 注意这里,testdb01 是 database-name
    "type": "jdbc",
    "jdbc": {
        "driver": "com.mysql.jdbc.Driver",
        "url": "jdbc:mysql://your-es-ip:3306/testdb01",
        "user": "your_jdbc_username",
        "password": "your_jdbc_passwd",
        "sql": "select id as _id,name,login_name from user",
        "index": "index_testdb01",
        "type": "user",
        "bulk_size": 100,
        "max_bulk_requests": 30,
        "bulk_timeout": "10s",
        "flush_interval": "5s",
        "schedule": "0 0-59 0-23 ? * *"
    }
}'

Reference article

endymecy.gitbooks.io
github-elasticsearch-jdbc


blair
209 声望31 粉丝

我是 Blair