Skip to content

Instantly share code, notes, and snippets.

Created October 21, 2011 12:16
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/1303673 to your computer and use it in GitHub Desktop.
Save anonymous/1303673 to your computer and use it in GitHub Desktop.
//CREATE INDEX is called the beginning of framework startup
private void createIndex(){
System.out.println("ElasticStore : preparing index " + globalIndexName);
boolean exists = getClient().admin().indices().prepareExists(globalIndexName).execute().actionGet().exists();
if( !exists){
Map<String,Object> settings = new HashMap<String, Object>();
settings.put(NUMBER_OF_REPLICAS_PROP_KEY, this.numberOfReplicas);
settings.put(NUMBER_OF_SHARDS_PROP_KEY, this.numberOfShards);
System.out.println(" >> Index did not exist , creating it ");
getClient().admin().indices().prepareCreate(globalIndexName)
.setSettings(settings)
.execute().actionGet();
getClient().admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet();
System.out.println(" >> index should have been created ");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment