System.out.println("Number of aliases: " + numberOfAliases);
if (numberOfAliases < BASE_ALIAS_COUNT) {
int diff = BASE_ALIAS_COUNT - numberOfAliases;
System.out.println("Adding " + diff + " more aliases to get to the start amount of " + BASE_ALIAS_COUNT + " aliases");
IndicesAliasesRequestBuilder builder = client.admin().indices().prepareAliases();
for (int i = 1; i <= diff; i++) {
builder.addAlias(INDEX_NAME, Strings.randomBase64UUID());
if (i % 1000 == 0) {
builder.execute().actionGet();
builder = client.admin().indices().prepareAliases();
}
}
if (!builder.request().getAliasActions().isEmpty()) {
builder.execute().actionGet();
}
} else if (numberOfAliases > BASE_ALIAS_COUNT) {
IndicesAliasesRequestBuilder builder = client.admin().indices().prepareAliases();
int diff = numberOfAliases - BASE_ALIAS_COUNT;
System.out.println("Removing " + diff + " aliases to get to the start amount of " + BASE_ALIAS_COUNT + " aliases");
List<AliasMetaData> aliases= client.admin().indices().prepareGetAliases("*")
.addIndices(INDEX_NAME)
.execute().actionGet().getAliases().get(INDEX_NAME);
for (int i = 0; i <= diff; i++) {
builder.removeAlias(INDEX_NAME, aliases.get(i).alias());
if (i % 1000 == 0) {
builder.execute().actionGet();
builder = client.admin().indices().prepareAliases();
}
}
if (!builder.request().getAliasActions().isEmpty()) {
builder.execute().actionGet();
}
}
numberOfAliases = countAliases(client);
System.out.println("Number of aliases: " + numberOfAliases);