// First time through, check the replication factor is correct...
ClusterHealthResponse health =
_elasticClient.admin().cluster().health(new ClusterHealthRequest(sIndexName)).actionGet();
ClusterIndexHealth indexStatus = health.getIndices().get(sIndexName);
if ((null != indexStatus) && (1 == indexStatus.getShards().size())) { // 1 shard => this is a "data local" index
int nNumNodes = health.getNumberOfDataNodes();
Builder localSettings = ImmutableSettings.settingsBuilder();
if (nNumNodes > 1) {
localSettings.put("number_of_replicas", nNumNodes - 1); // (ie shard=1 + replicas==num_nodes)
}
else {
localSettings.put("number_of_replicas", 1); // (System doesn't work very well if has no replicas?)
}
UpdateSettingsUtils.updateSettings(_elasticClient.admin().indices(), sIndexName, localSettings.build());
//(Wait for above operation to be completed)
_elasticClient.admin().cluster().health(new ClusterHealthRequest(sIndexName).waitForYellowStatus()).actionGet();
}
else if ((null != indexStatus) && (indexStatus.getNumberOfReplicas() > 1)) { // Multi shard index, just need to check there aren't too many replicas for nodes
int nNumNodes = health.getNumberOfDataNodes();
int nReplicas = indexStatus.getNumberOfReplicas();
int nNodesPerReplica = properties.getElasticNodesPerReplica();
if ((nNumNodes > 0) && (nNodesPerReplica > 0)) {
int nNewReplicas = (nNumNodes + nNodesPerReplica-1)/nNodesPerReplica;
// (ie round up)
int nMaxReplicas = properties.getElasticMaxReplicas();