public static void deleteElasticSearchIndex(Map configuration) {
// TODO refactor to pull graph. from some static reference
String indexName = (String) configuration.get("graph." + GraphConfiguration.SEARCH_INDEX_PROP_PREFIX + "." + ElasticSearchSearchIndexBase.CONFIG_INDEX_NAME);
String[] esLocations = ((String) configuration.get("graph." + GraphConfiguration.SEARCH_INDEX_PROP_PREFIX + "." + ElasticSearchSearchIndexBase.CONFIG_ES_LOCATIONS)).split(",");
LOGGER.debug("BEGIN deleting elastic search index: " + indexName);
TransportClient client = new TransportClient();
for (String esLocation : esLocations) {
String[] locationSocket = esLocation.split(":");
String host = locationSocket[0];
String port = locationSocket.length > 1 ? locationSocket[1] : "9300";
client.addTransportAddress(new InetSocketTransportAddress(host, Integer.parseInt(port)));
}
LOGGER.info("index %s exists?", indexName);
IndicesExistsRequest existsRequest = client.admin().indices().prepareExists(indexName).request();
if (client.admin().indices().exists(existsRequest).actionGet().isExists()) {
LOGGER.info("index %s exists... deleting!", indexName);
DeleteIndexResponse response = client.admin().indices().delete(new DeleteIndexRequest(indexName)).actionGet();
if (!response.isAcknowledged()) {
LOGGER.error("Failed to delete elastic search index named %s", indexName);
}
}
LOGGER.debug("END deleting elastic search index: " + indexName);
client.close();
}