logger.info("--> aliasing index [test] with [alias1]");
client1.admin().indices().prepareAliases().addAlias("test", "alias1").execute().actionGet();
logger.info("--> indexing against [alias1], should work now");
IndexResponse indexResponse = client1.index(indexRequest("alias1").type("type1").id("1").source(source("1", "test"))).actionGet();
assertThat(indexResponse.index(), equalTo("test"));
logger.info("--> creating index [test]");
client1.admin().indices().create(createIndexRequest("test_x")).actionGet();
logger.info("--> running cluster_health");
clusterHealth = client1.admin().cluster().health(clusterHealthRequest().waitForGreenStatus()).actionGet();
logger.info("--> done cluster_health, status " + clusterHealth.status());
assertThat(clusterHealth.timedOut(), equalTo(false));
assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.GREEN));
logger.info("--> remove [alias1], Aliasing index [test_x] with [alias1]");
client1.admin().indices().aliases(indexAliasesRequest().removeAlias("test", "alias1").addAlias("test_x", "alias1")).actionGet();
Thread.sleep(300);
logger.info("--> indexing against [alias1], should work against [test_x]");
indexResponse = client1.index(indexRequest("alias1").type("type1").id("1").source(source("1", "test"))).actionGet();
assertThat(indexResponse.index(), equalTo("test_x"));
}