diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunner.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunner.java index 41284620bef..6251980fc21 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunner.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunner.java @@ -546,14 +546,16 @@ public class IndexLifecycleRunner { private static IndexMetaData.Builder removePolicyForIndex(IndexMetaData indexMetadata) { Settings idxSettings = indexMetadata.getSettings(); Settings.Builder newSettings = Settings.builder().put(idxSettings); + boolean notChanged = true; - newSettings.remove(LifecycleSettings.LIFECYCLE_NAME_SETTING.getKey()); - newSettings.remove(LifecycleSettings.LIFECYCLE_SKIP_SETTING.getKey()); - newSettings.remove(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS_SETTING.getKey()); + notChanged &= Strings.isNullOrEmpty(newSettings.remove(LifecycleSettings.LIFECYCLE_NAME_SETTING.getKey())); + notChanged &= Strings.isNullOrEmpty(newSettings.remove(LifecycleSettings.LIFECYCLE_SKIP_SETTING.getKey())); + notChanged &= Strings.isNullOrEmpty(newSettings.remove(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS_SETTING.getKey())); + long newSettingsVersion = notChanged ? indexMetadata.getSettingsVersion() : 1 + indexMetadata.getSettingsVersion(); IndexMetaData.Builder builder = IndexMetaData.builder(indexMetadata); builder.removeCustom(ILM_CUSTOM_METADATA_KEY); - return builder.settings(newSettings).settingsVersion(1 + indexMetadata.getSettingsVersion()); + return builder.settings(newSettings).settingsVersion(newSettingsVersion); } private void markPolicyDoesNotExist(String policyName, Index index, LifecycleExecutionState executionState) {