Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Basic sketch for renaming an index in Elasticsearch
# create an index with some state (in this case, a mapping)
curl -X POST localhost:9200/test-original -d '{"mappings":{"wine":{"properties":{"designation":{"type":"string"},"full_name":{"type":"string"},"winery":{"type":"string"},"style":{"index":"no","type":"string"},"vintage":{"index":"no","type":"string"},"restaurant_ids":{"index":"no","type":"string"},"appellation":{"type":"string"},"vineyard_name":{"type":"string"},"variety_id":{"index":"no","type":"string"},"country":{"type":"string"}}}}}'
# => {"ok":true,"acknowledged":true}
# verify the mapping
curl localhost:9200/test-original/_mapping
# => {"test-original":{"wine":{"properties":{"appellation":{"type":"string"},"country":{"type":"string"},"designation":{"type":"string"},"full_name":{"type":"string"},"restaurant_ids":{"type":"string","index":"no"},"style":{"type":"string","index":"no"},"variety_id":{"type":"string","index":"no"},"vineyard_name":{"type":"string"},"vintage":{"type":"string","index":"no"},"winery":{"type":"string"}}}}}
# copy the index directory to rename it
rsync -av test-original/ test-renamed
# => building file list ... done
# created directory test-renamed
# [...snip...]
# sent 3653 bytes received 834 bytes 8974.00 bytes/sec
# total size is 1033 speedup is 0.23
# check the new index and its mapping -- fail because elasticsearch hasn't imported it yet
curl localhost:9200/test-renamed/_mapping
# => {"error":"IndexMissingException[[test-renamed] missing]","status":404}
# restart elasticsearch
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.elasticsearch.plist
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.elasticsearch.plist
# check the new index and its mapping -- success
curl localhost:9200/test-renamed/_mapping
# => {"test-renamed":{"wine":{"properties":{"appellation":{"type":"string"},"country":{"type":"string"},"designation":{"type":"string"},"full_name":{"type":"string"},"restaurant_ids":{"type":"string","index":"no"},"style":{"type":"string","index":"no"},"variety_id":{"type":"string","index":"no"},"vineyard_name":{"type":"string"},"vintage":{"type":"string","index":"no"},"winery":{"type":"string"}}}}}
@clarissacastella
Copy link

clarissacastella commented Jun 4, 2015

Unfortunely, did not work on my machine:

ccx@ccx-K45VM:~/work/nlp-tools/TM/es-tools$ rsync -av test-original/ test-renamed
sending incremental file list
rsync: change_dir "/home/ccx/work/nlp-tools/TM/es-tools//test-original" failed: No such file or directory (2)

sent 20 bytes received 12 bytes 64.00 bytes/sec
total size is 0 speedup is 0.00
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1183) [sender=3.1.0]

@kwizzn
Copy link

kwizzn commented Oct 30, 2015

Just what I needed, even 2 years later. 👍

@johan-boule
Copy link

johan-boule commented Nov 4, 2017

I hate all your mackintoshisms.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment