Skip to content

Instantly share code, notes, and snippets.

@alexcheng1982
Created June 25, 2015 23:25
Show Gist options
  • Save alexcheng1982/52c7237c061d380fb001 to your computer and use it in GitHub Desktop.
Save alexcheng1982/52c7237c061d380fb001 to your computer and use it in GitHub Desktop.
Elasticsearch - Create index when not exist
private void createIndex() {
boolean indexExists = client.admin().indices().prepareExists(INDEX_NAME).execute().actionGet().isExists();
if (!indexExists) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Index {} doesn't exist, create it now.", INDEX_NAME);
}
client.admin().indices().prepareCreate(INDEX_NAME).execute();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment