Created
August 23, 2013 18:46
-
-
Save nz/6322673 to your computer and use it in GitHub Desktop.
Basic sketch for renaming an index in Elasticsearch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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"}}}}} |
Just what I needed, even 2 years later. 👍
I hate all your mackintoshisms.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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]