如何在弹性搜索中复制索引



我正在进行弹性搜索,我想在本地弹性搜索实例上创建与在生产实例上创建的索引相同的索引,具有相同类型的映射和设置,我能想到的一种方法是设置相同的映射,有没有其他更好的方法将索引元数据复制到本地,谢谢

只需向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)

即使在ES的不同版本之间复制索引,这也能跨版本工作

我使用了一个docker图像,详细信息-https://hub.docker.com/r/taskrabbit/elasticsearch-dump/(使用docker镜像的优点是,您不需要在系统上安装node和npm,只有运行docker就足够了(

一旦安装了docker并提取了taskrabbit映像,您就可以运行docker映像,使用run命令将远程服务器上的弹性搜索索引转储到本地,反之亦然:

sudo docker run --net=host --rm -ti taskrabbit/elasticsearch-dump --input=http://<remote-elastic>/testindex --output=http://<your-machine-ip>:9200/testindex --type=mapping
sudo docker run --net=host --rm -ti taskrabbit/elasticsearch-dump --input=http://<remote-elastic>/testindex --output=http://<your-machine-ip>:9200/testindex --type=data

要将索引从本地弹性搜索复制到远程,只需反转输入和输出即可。第一个命令复制映射,而第二个命令转储数据。

最新更新