diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportUnfollowAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportUnfollowAction.java index a42ff658dc9e1..3a158aceddb2d 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportUnfollowAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportUnfollowAction.java @@ -105,18 +105,19 @@ static ClusterState unfollow(String followerIndex, ClusterState current) { } } - IndexMetaData.Builder newIMD = IndexMetaData.builder(followerIMD); // Remove index.xpack.ccr.following_index setting Settings.Builder builder = Settings.builder(); builder.put(followerIMD.getSettings()); builder.remove(CcrSettings.CCR_FOLLOWING_INDEX_SETTING.getKey()); - newIMD.settings(builder); + final IndexMetaData.Builder newIndexMetaData = IndexMetaData.builder(followerIMD); + newIndexMetaData.settings(builder); + newIndexMetaData.settingsVersion(followerIMD.getSettingsVersion() + 1); // Remove ccr custom metadata - newIMD.removeCustom(Ccr.CCR_CUSTOM_METADATA_KEY); + newIndexMetaData.removeCustom(Ccr.CCR_CUSTOM_METADATA_KEY); MetaData newMetaData = MetaData.builder(current.metaData()) - .put(newIMD) + .put(newIndexMetaData) .build(); return ClusterState.builder(current) .metaData(newMetaData) diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/TransportUnfollowActionTests.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/TransportUnfollowActionTests.java index 9b9d088eea332..93987a7306f45 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/TransportUnfollowActionTests.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/TransportUnfollowActionTests.java @@ -30,8 +30,10 @@ public class TransportUnfollowActionTests extends ESTestCase { public void testUnfollow() { + final long settingsVersion = randomNonNegativeLong(); IndexMetaData.Builder followerIndex = IndexMetaData.builder("follow_index") .settings(settings(Version.CURRENT).put(CcrSettings.CCR_FOLLOWING_INDEX_SETTING.getKey(), true)) + .settingsVersion(settingsVersion) .numberOfShards(1) .numberOfReplicas(0) .state(IndexMetaData.State.CLOSE) @@ -47,6 +49,7 @@ public void testUnfollow() { IndexMetaData resultIMD = result.metaData().index("follow_index"); assertThat(resultIMD.getSettings().get(CcrSettings.CCR_FOLLOWING_INDEX_SETTING.getKey()), nullValue()); assertThat(resultIMD.getCustomData(Ccr.CCR_CUSTOM_METADATA_KEY), nullValue()); + assertThat(resultIMD.getSettingsVersion(), equalTo(settingsVersion + 1)); } public void testUnfollowIndexOpen() {