阿里云Dataworks将odps数据同步到es(7版本)采用inedx与 updata 方式 教程

采用update 时 需要指定主键 又不能使用生成的主键(_id) 所以 只能在odps 中引入主键

  1. 创建索引与mapping
#!/bin/bash
#********************************************************************#
##author:????
##create time:2021-02-03 15:20:11
#********************************************************************#
# 根据条件查询数据
curl -XGET -u"用户名":"密码" '主机:端口号/index_test_es_update/_search' -H 'Content-Type: application/json' -d '{
"query": {
"term": {
"cons_no": "123456"
}
}
}
'
# 查看所有索引 
curl -XGET -u"用户名":"密码" '主机:端口号/ index_test_es_update/_cat/indices?pretty&v'
# 删除索引
curl -XDELETE -u"用户名":"密码" '主机:端口号/index_test_es_update?pretty'
# 查看mapping
curl -XGET -u"用户名":"密码" '主机:端口号/index_test_es_update /_mapping?pretty'
# 创建索引 注意dataworks 中 es column id 类型为 id 不要在创建索引时添加
curl -XPUT -u"用户名":"密码" '主机:端口号/index_test_es_update?pretty' -H 'Content-Type: application/json' -d '
{
"mappings": {
"properties": {
"id": {
"type": "keyword"
},
"data_dt": {
"type": "keyword"
},
"aaa": {
"type": "keyword",
"null_value": "NULL"
}
}
}
}
'
  1. index 方式脚本同步
{
"type": "job",
"steps": [
{
"stepType": "odps",
"parameter": {
"datasource": "odps_first",
"column": [
"id",
"data_dt",
"aaa",
],
"splitPK": "id",
"emptyAsNull": false,
"table": "test_es_index"
},
"name": "Reader",
"category": "reader"
},
{
"stepType": "elasticsearch",
"parameter": {
"column": [
{
"name": "id",
"type": "keyword"
},
{
"name": "data_dt",
"type": "keyword"
},
{
"name": "aaa",
"type": "keyword"
}
],
"index": "index_test_es_index",
"aliasMode": "append",
"type": "_doc",
"splitter": "",
"timeout": 600000,
"multiThread": true,
"actionType": "index",
"cleanup": false,
"datasource": "ES",
"discovery": false,
"trySize": 30,
"alias": "",
"ignoreParseError": false,
"dynamic": true,
"batchSize": 1000,
"compression": true,
"ignoreWriteError": false
},
"name": "Writer",
"category": "writer"
}
],
"version": "2.0",
"order": {
"hops": [
{
"from": "Reader",
"to": "Writer"
}
]
},
"setting": {
"errorLimit": {
"record": ""
},
"speed": {
"concurrent": 2,
"throttle": false
}
}
}
  1. update方式脚本同步
{
"type": "job",
"steps": [
{
"stepType": "odps",
"parameter": {
"datasource": "odps_first",
"column": [
"id",
"id",
"data_dt",
"aaa",
],
"splitPK": "id",
"emptyAsNull": false,
"table": "test_es_update"
},
"name": "Reader",
"category": "reader"
},
{
"stepType": "elasticsearch",
"parameter": {
"column": [
{
"name": "id",
"type": "id"
},
{
"name": "id",
"type": "keyword"
},
{
"name": "data_dt",
"type": "keyword"
},
{
"name": "aaa",
"type": "keyword"
}
],
"index": "index_test_es_update",
"aliasMode": "append",
"type": "_doc",
"splitter": "",
"timeout": 600000,
"multiThread": true,
"actionType": "update",
"cleanup": false,
"datasource": "ES",
"discovery": false,
"trySize": 30,
"alias": "",
"ignoreParseError": false,
"dynamic": true,
"batchSize": 1000,
"compression": true,
"ignoreWriteError": false
},
"name": "Writer",
"category": "writer"
}
],
"version": "2.0",
"order": {
"hops": [
{
"from": "Reader",
"to": "Writer"
}
]
},
"setting": {
"errorLimit": {
"record": ""
},
"speed": {
"concurrent": 2,
"throttle": false
}
}
}

  1. 参数说明
    “index”: “index_test_es_index”, // 索引
    “type”: “_doc”, //索引类型
    “timeout”: 600000, //超时时间
    “actionType”: “index”, //数据插入方式 inedx or update
    “cleanup”: false, // 插入前是否清除之前数据 false 不清除
    “dynamic”: true, //true,则使用Elasticsearch的自动mappings,而非使用数据集成的mappings。
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值