1 回答
TA贡献2051条经验 获得超10个赞
upsert
通过脚本的正确方法是不使用该部分,doc
而仅使用该script
部分。upsert
如果您想在同一命令中更新插入和更新,您还需要该部分。事情是这样的:
actions = [{
"_op_type":"update",
"_index": "test-data",
"_type": "test-test-data",
"_id": test_row ['testId'],
"upsert": {
"DataIds": test_row ['DataIds']
},
"script": {
"source": "ctx._source.DataIds.add(params.DataIds)",
"lang": "painless",
"params": {
"DataIds":test_row ['DataIds']
}
}
} for test_row in temp_list
]
另一种方法是使用scripted_upsert
actions = [{
"_op_type":"update",
"_index": "test-data",
"_type": "test-test-data",
"_id": test_row ['testId'],
"upsert": {},
"scripted_upsert": true,
"script": {
"source": "if (ctx._source.DataIds == null) { ctx._source.DataIds = []; } ctx._source.DataIds.add(params.DataIds)",
"lang": "painless",
"params": {
"DataIds":test_row ['DataIds']
}
}
} for test_row in temp_list
]
添加回答
举报