quester
quester

Reputation: 11

How to duplicate index in elastic search?

I am working on elastic search and I want to create same index on local elastic search instance as it is created on production instance, with same type of mapping and settings, one way I can think of is setting same mappings, is there any other better way of copying index metadata to local, thanks

Upvotes: 1

Views: 2892

Answers (2)

Kashish Soni
Kashish Soni

Reputation: 171

Simply sending a GET request to https://source-es-ip:port/index_name/_mappings and PUT the output to https://destination-es-ip:port/index_name

Copying the data can be achieved by the Elasticsearch Reindex API, For reference you can see this link. For example, To achieve this I would use this 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)

And this works across version even while copying the indexes across different versions of ES

Upvotes: 1

soumitra goswami
soumitra goswami

Reputation: 891

I use a docker image for this , details - https://hub.docker.com/r/taskrabbit/elasticsearch-dump/ (the advantage of using docker image is, you don't need to install node and npm on your system, only having docker running is enough)

Once docker is installed and you have pulled the taskrabbit image, you can run the docker image to get a dump of the elasticsearch index on your remote server to local and vice versa using run commands :

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

to copy an index from your local elasticsearch to remote just reverse the input and output. The first command copies the mapping while the second dumps the data.

Upvotes: 0

Related Questions