Clone an Elasticsearch Index
1 min readDec 30, 2019
It’s not hard, but no one ever seems to explicitly write this down.
1. Create the destination index with the same settings.
- Grab the index config from
somehost:9200/someindex
- Pare out unwanted index config, eg: source name, uuid, creation date
- Cram the config into a new index
curl -XPUT 'http://localhost:9200/someindex_copy' \
-H 'Content-Type: application/json' \
-d "$(curl http://localhost:9200/someindex | jq '.someindex | del(.settings.index.provided_name, .settings.index.creation_date, .settings.index.uuid, .settings.index.version)')"
2. Call the Reindex API
curl -X POST "localhost:9200/_reindex?pretty" -H 'Content-Type: application/json' -d'
{
"source": {
"index": "someindex"
},
"dest": {
"index": "someindex_copy"
}
}
'
There’s all sorts of good stuff that the Reindex API can do, like reindex from remote, filtering, transforms, etc.
Docs: https://www.elastic.co/guide/en/elasticsearch/reference/7.5/docs-reindex.html
3. That’s It.
That’s the bones of it. Fill your boots.