from elasticsearch import Elasticsearch
from elasticsearch import helpers
# elasticsearch集群服务器的地址
es_servers = [
'10.123.179.102:9200','10.123.179.103:9200','10.123.179.104:9200','10.123.179.105:9200'
]
# 创建elasticsearch客户端
es = Elasticsearch(
es_servers,
# 启动前嗅探es集群服务器
sniff_on_start=True,
# es集群服务器结点连接异常时是否刷新es节点信息
sniff_on_connection_fail=True,
# 每60秒刷新节点信息
sniffer_timeout=60,
#超时时间
timeout=10000,
#重试次数
max_retries=10,
#超时时重试
retry_on_timeout=True
)
#更新数据集
data = [{
"_op_type": 'update',
"_index": 'test_index',
"_type": '_doc',
"_id": 11,
"doc_as_upsert":True,
"doc": {"newkey": 'newvalue'}
},{
"_op_type": 'update',
"_index": 'test_index',
"_type": '_doc',
"_id": 12,
"doc_as_upsert":True,
"doc": {"newkey": 'newvalue'}
},{
"_op_type": 'update',
"_index": 'test_index',
"_type": '_doc',
"_id": 13,
"doc_as_upsert":True,
"doc": {"newkey": 'newvalue'}
},{
"_op_type": 'update',
"_index": 'test_index',
"_type": '_doc',
"_id": 14,
"doc_as_upsert":True,
"doc": {"newkey": 'newvalue'}
}
]
helpers.bulk(es, data)
Python操作es批量upsert数据
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 参考资料 Elasticsearch API Documentation Global options 一、Ign...
- 接第7节 5、删除文档&索引 删除类型方法或路径参数删除文档DELETE customer/external/1删...
- 注意点:现在kibana/elasticsearch最新版本为7.0,与5.2.0的语法有出入,需要注意 语法,自...
- 内容来自《ES 权威指南》 [TOC] 一、索引文档 文档通过 index API 被索引--使数据可以被存储和搜...
- 一. es导入导出测试 1. 创建snapshot文件夹 mkdir /mnt/ssd1 chown -R es:...