如何在弹性搜索中复制索引? 即使在跨ES的不同版本复制索引时,这也适用于所有版本

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

TT30824 回答:如何在弹性搜索中复制索引? 即使在跨ES的不同版本复制索引时,这也适用于所有版本

我为此使用docker映像,详细信息-https://hub.docker.com/r/taskrabbit/elasticsearch-dump/ (使用docker映像的优点是,您无需在系统上安装node和npm,只需运行docker就足够了)

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

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

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

,

只需将GET请求发送到https://source-es-ip:port/index_name/_mappings 并将输出放入https://destination-es-ip:port/index_name

复制数据可以通过Elasticsearch Reindex API实现, 作为参考,您可以看到此link。 例如,要实现此目的,我将使用此python Script-

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的不同版本复制索引时,这也适用于所有版本

本文链接:https://www.f2er.com/3125882.html

大家都在问