diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/utils/MlIndexAndAlias.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/utils/MlIndexAndAlias.java index 5c98904095740..82d5780ae9066 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/utils/MlIndexAndAlias.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/utils/MlIndexAndAlias.java @@ -118,7 +118,7 @@ public static void createIndexAndAliasIfNecessary(Client client, // The initial index name must be suitable for rollover functionality. String firstConcreteIndex = indexPatternPrefix + "-000001"; String[] concreteIndexNames = - resolver.concreteIndexNames(clusterState, IndicesOptions.lenientExpandOpen(), indexPattern); + resolver.concreteIndexNames(clusterState, IndicesOptions.lenientExpandHidden(), indexPattern); Optional indexPointedByCurrentWriteAlias = clusterState.getMetadata().hasAlias(alias) ? clusterState.getMetadata().getIndicesLookup().get(alias).getIndices().stream().findFirst() : Optional.empty(); @@ -241,11 +241,17 @@ private static void createFirstConcreteIndex(Client client, ActionListener.wrap( createIndexResponse -> listener.onResponse(true), createIndexFailure -> { - // If it was created between our last check, and this request being handled, we should add the alias - // Adding an alias that already exists is idempotent. So, no need to double check if the alias exists - // as well. if (ExceptionsHelper.unwrapCause(createIndexFailure) instanceof ResourceAlreadyExistsException) { - updateWriteAlias(client, alias, null, index, listener); + // If it was created between our last check and this request being handled, we should add the alias + // if we were asked to add it on creation. Adding an alias that already exists is idempotent. So + // no need to double check if the alias exists as well. But if we weren't asked to add the alias + // on creation then we should leave it up to the caller to decide what to do next (some call sites + // already have more advanced alias update logic in their success handlers). + if (addAlias) { + updateWriteAlias(client, alias, null, index, listener); + } else { + listener.onResponse(true); + } } else { listener.onFailure(createIndexFailure); } diff --git a/x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/xpack/ml/integration/JobStorageDeletionTaskIT.java b/x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/xpack/ml/integration/JobStorageDeletionTaskIT.java index 061023f04e457..3b3ea7696b9a7 100644 --- a/x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/xpack/ml/integration/JobStorageDeletionTaskIT.java +++ b/x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/xpack/ml/integration/JobStorageDeletionTaskIT.java @@ -54,7 +54,7 @@ */ public class JobStorageDeletionTaskIT extends BaseMlIntegTestCase { - private static long bucketSpan = AnalysisConfig.Builder.DEFAULT_BUCKET_SPAN.getMillis(); + private static final long bucketSpan = AnalysisConfig.Builder.DEFAULT_BUCKET_SPAN.getMillis(); private static final String UNRELATED_INDEX = "unrelated-data"; private JobResultsProvider jobResultsProvider; @@ -179,7 +179,7 @@ public void testDeleteDedicatedJobWithDataInShared() throws Exception { .indices() .prepareGetIndex() .setIndices(dedicatedIndex) - .setIndicesOptions(IndicesOptions.LENIENT_EXPAND_OPEN) + .setIndicesOptions(IndicesOptions.LENIENT_EXPAND_OPEN_CLOSED_HIDDEN) .get() .indices().length, equalTo(0));