elasticsearch - 如何在弹性搜索中复制索引?
问题描述
我正在研究弹性搜索,我想在本地弹性搜索实例上创建与在生产实例上创建相同的索引,具有相同类型的映射和设置,我能想到的一种方法是设置相同的映射,还有其他更好的吗将索引元数据复制到本地的方法,谢谢
解决方案
只需将 GET 请求发送到https://source-es-ip:port/index_name/_mappings 并将输出放到https://destination-es-ip:port/index_name
复制数据可以通过 Elasticsearch Reindex API 来实现,参考可以看这个链接。例如,为了实现这一点,我将使用这个 python 脚本-
from elasticsearch import Elasticsearch
from elasticsearch.helpers import reindex
import urllib3
urllib3.disable_warnings()
es_source = Elasticsearch(hosts=['ip:port'],<other params>)
es_target = Elasticsearch(hosts=['ip:port'],<other params>)
for index in es.indices.get('<index name/pattern>')
r = reindex(es_source, source_index=index, target_index=index, target_client=es_target, chunk_size=500)
print(r)