Skip to content

Instantly share code, notes, and snippets.

Created October 21, 2011 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/1303712 to your computer and use it in GitHub Desktop.
Save anonymous/1303712 to your computer and use it in GitHub Desktop.
public void putMapping(String typeName, XContentBuilder mappingBuilder){
System.out.println(" ----- > putMapping ");
try {
System.out.println(" >> taking index down --> " + this.globalIndexName);
getClient().admin().indices().prepareClose(globalIndexName).execute().actionGet();
System.out.println(" >> sending PUT MAPPING : " );
System.out.println(mappingBuilder.string());
getClient().admin().indices()
.preparePutMapping().setType(typeName)
.setSource(mappingBuilder.string()).execute().actionGet();
System.out.println( " >> waiting for green status .... >> ");
getClient().admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet();
//take index back up
System.out.println(" >> reopening index " + this.globalIndexName);
getClient().admin().indices().prepareOpen(globalIndexName).execute().actionGet();
} catch (ElasticSearchException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment