diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/metadata/PrelertMetadata.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/metadata/PrelertMetadata.java index 380e3a001c5..fc59699384f 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/metadata/PrelertMetadata.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/metadata/PrelertMetadata.java @@ -363,9 +363,13 @@ public class PrelertMetadata implements MetaData.Custom { } } - - // Once a job goes into Deleting, it cannot be changed if (previous.getStatus().equals(JobStatus.DELETING)) { + // If we're already Deleting there's nothing to do + if (jobStatus.equals(JobStatus.DELETING)) { + return this; + } + + // Once a job goes into Deleting, it cannot be changed throw new ElasticsearchStatusException("Cannot change status of job [" + jobId + "] to [" + jobStatus + "] because " + "it is currently in [" + JobStatus.DELETING + "] status.", RestStatus.CONFLICT); }