Skip to content

Instantly share code, notes, and snippets.

@sfussenegger
Last active December 23, 2015 06:09
Show Gist options
  • Save sfussenegger/6591653 to your computer and use it in GitHub Desktop.
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
#!/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