Last active
December 23, 2015 06:09
-
-
Save sfussenegger/6591653 to your computer and use it in GitHub Desktop.
Groovy script to copy settings and mappings from one elasticsearch cluster to another
This file contains 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
#!/usr/bin/env groovy | |
import groovy.json.* | |
/* | |
* usage: | |
* | |
* cd `mktemp -d` | |
* | |
* curl -s -XGET 'http://localhost:9200/_cluster/state?pretty=true&filter_nodes=true&filter_routing_table=true&filter_blocks=true' \ | |
* | indices.groovy | |
* for index in *; do | |
* curl -XDELETE "http://localhost:9200/${index}" | |
* curl -XPUT "http://localhost:9200/${index}" -d @create-index-${index}.json | |
* done | |
* | |
* TODO move curl invocations into script | |
*/ | |
def state = new JsonSlurper().parseText(System.in.text) | |
state.metadata.indices.each { name, data -> | |
data.keySet().retainAll(["mappings", "settings"]) | |
def output = new JsonBuilder(data).toPrettyString() | |
new File(name).write(output) | |
println "wrote ${name}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment