本文主要是介绍elasticsearch 小规模数据 跨集群迁移,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
迁移方法1,通过代码迁移,优点不需要改动任何集群配置和重启器群:
from elasticsearch import Elasticsearch
from elasticsearch import helpersdef get_all_data(table, query_dsl,scroll='5m',timeout='1m'):es = Elasticsearch([{'host': "IP", 'port': PORT, "http_auth": "user:passwd"}])es_result = helpers.scan(client=es,query=query_dsl,scroll=scroll,index=table,timeout=timeout)return es_resultdef batch_data(data_list, index_name, _id_name=None):""" 批量写入数据 """es = Elasticsearch([{'host': "IP", 'port': PORT, "http_auth": "user:passwd"}])if _id_name:action = [{"_index": index_name,"_id": data_list[i][_id_name],'_type': '_doc',"_source": data_list[i]} for i in range(len(data_list))]else:action = [{"_index": index_name,'_type': '_doc',"_source": data_list[i]} for i in range(len(data_list))]helpers.bulk(es, action)query_dsl = {"query":{"match_all":{}}
}es_result = get_all_data("index_name",query_dsl)
result = []
for each in es_result:result.append(each.get("_source"))if len(result)>3000:batch_data(result,"index_name",_id_name="news_id")result.clear()
迁移方式2:Elasticdump
迁移方式3:reindex
参考:es数据跨集群的两种迁移方式_一只行走鸟的博客-CSDN博客_es reindex跨集群
这篇关于elasticsearch 小规模数据 跨集群迁移的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!