DataX写入ElasticSearch
1 快速介绍
数据导入elasticsearch的插件
2 实现原理
使用elasticsearch的rest api接口, 批量把从reader读入的数据写入elasticsearch
3功能说明
3.1配置样例
1{ 2 "job": { 3 "setting": { 4 "speed": { 5 "channel": 1, 6 "record": -1, 7 "byte": -1 8 } 9 }, 10 "content": [{ 11 "reader": { 12 "name": "mysqlreader", 13 "parameter": { 14 "username": "root", 15 "password": "1234qwer", 16 "column": [ 17 "id", 18 "name" 19 ], 20 "splitPk": "id", 21 "connection": [{ 22 "table": [ 23 "datax_test" 24 ], 25 "jdbcUrl": [ 26 "jdbc:mysql://localhost:3306/test" 27 ] 28 }] 29 } 30 }, 31 "writer": { 32 "name": "elasticsearchwriter", 33 "parameter": { 34 "endpoint": "http://localhost:9200", 35 "accessId": "admin", 36 "accessKey": "123456", 37 "index": "test-datax", 38 "type": "default", 39 "cleanup": true, 40 "settings": { 41 "index": { 42 "number_of_shards": 1, 43 "number_of_replicas": 0 44 } 45 }, 46 "discovery": false, 47 "batchSize": 1000, 48 "splitter": ",", 49 "column": [{ 50 "name": "id", 51 "type": "id" 52 }, 53 { 54 "name": "name", 55 "type": "string" 56 } 57 ] 58 } 59 } 60 }] 61 } 62}
参数说明
• endpoint
• 描述:ElasticSearch的连接地址
• 必选:是
• 默认值:无
• accessId
• 描述:http auth中的user
• 必选:否
• 默认值:空
• accessKey
• 描述:http auth中的password
• 必选:否
• 默认值:空
• index
• 描述:elasticsearch中的index名
• 必选:是
• 默认值:无
• type
• 描述:elasticsearch中index的type名
• 必选:否
• 默认值:index名
• cleanup
• 描述:是否删除原表
• 必选:否
• 默认值:false
• batchSize
• 描述:每次批量数据的条数
• 必选:否
• 默认值:1000
• trySize
• 描述:失败后重试的次数
• 必选:否
• 默认值:30
• timeout
• 描述:客户端超时时间
• 必选:否
• 默认值:600000
• discovery
• 描述:启用节点发现将(轮询)并定期更新客户机中的服务器列表。
• 必选:否
• 默认值:false
• compression
• 描述:http请求,开启压缩
• 必选:否
• 默认值:true
• multiThread
• 描述:http请求,是否有多线程
• 必选:否
• 默认值:true
• ignoreWriteError
• 描述:忽略写入错误,不重试,继续写入
• 必选:否
• 默认值:false
• ignoreParseError
• 描述:忽略解析数据格式错误,继续写入
• 必选:否
• 默认值:true
• alias
• 描述:数据导入完成后写入别名
• 必选:否
• 默认值:无
• aliasMode
• 描述:数据导入完成后增加别名的模式,append(增加模式), exclusive(只留这一个)
• 必选:否
• 默认值:append
• settings
• 描述:创建index时候的settings, 与elasticsearch官方相同
• 必选:否
• 默认值:无
• splitter
• 描述:如果插入数据是array,就使用指定分隔符
• 必选:否
• 默认值:-,-
• column
• 描述:elasticsearch所支持的字段类型,样例中包含了全部
• 必选:是
• dynamic
• 描述: 不使用datax的mappings,使用es自己的自动mappings
• 必选: 否
• 默认值: false
执行
./datax.py /Users/FengZhen/Desktop/Hadoop/dataX/json/ES/1.write2ES.json
看结果
1FengZhendeMacBook-Pro:bin FengZhen$ curl -XGET 'http://localhost:9200/test-datax/default/_search?pretty' 2{ 3"took" : 16, 4"timed_out" : false, 5"_shards" : { 6"total" : 1, 7"successful" : 1, 8"skipped" : 0, 9"failed" : 0 10}, 11"hits" : { 12"total" : 2, 13"max_score" : 1.0, 14"hits" : [ 15{ 16"_index" : "test-datax", 17"_type" : "default", 18"_id" : "1", 19"_score" : 1.0, 20"_source" : { 21"name" : "fz" 22} 23}, 24{ 25"_index" : "test-datax", 26"_type" : "default", 27"_id" : "2", 28"_score" : 1.0, 29"_source" : { 30"name" : "dx" 31} 32} 33] 34} 35}