From 37b664f1b61104db061a2787fc08499e31087dec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88rg=20Prante?= Date: Sat, 23 Feb 2019 15:26:36 +0100 Subject: [PATCH] fix wait for active shards --- .../org/xbib/elx/common/AbstractExtendedClient.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/elx-common/src/main/java/org/xbib/elx/common/AbstractExtendedClient.java b/elx-common/src/main/java/org/xbib/elx/common/AbstractExtendedClient.java index 4b97f4a..586013b 100644 --- a/elx-common/src/main/java/org/xbib/elx/common/AbstractExtendedClient.java +++ b/elx-common/src/main/java/org/xbib/elx/common/AbstractExtendedClient.java @@ -438,14 +438,11 @@ public abstract class AbstractExtendedClient implements ExtendedClient { public boolean waitForRecovery(String index, long maxWaitTime, TimeUnit timeUnit) { ensureActive(); ensureIndexGiven(index); - RecoveryRequest recoveryRequest = new RecoveryRequest(); - recoveryRequest.indices(index); - recoveryRequest.activeOnly(true); - RecoveryResponse recoveryResponse = client.execute(RecoveryAction.INSTANCE, recoveryRequest).actionGet(); - if (recoveryResponse.hasRecoveries()) { - int shards = recoveryResponse.getTotalShards(); - logger.info("shards = {}", shards); - logger.info(recoveryResponse.shardRecoveryStates()); + GetSettingsRequest settingsRequest = new GetSettingsRequest(); + settingsRequest.indices(index); + GetSettingsResponse settingsResponse = client.execute(GetSettingsAction.INSTANCE, settingsRequest).actionGet(); + int shards = settingsResponse.getIndexToSettings().get(index).getAsInt("index.number_of_shards", -1); + if (shards > 0) { TimeValue timeout = toTimeValue(maxWaitTime, timeUnit); ClusterHealthRequest clusterHealthRequest = new ClusterHealthRequest() .indices(new String[]{index})