**Build scan:**
https://gradle-enterprise.elastic.co/s/x57fzeiwekdve/tests/:x-pack:plugin:ccr:qa:multi-cluster:follow-cluster/org.elasticsearch.xpack.ccr.AutoFollowIT/testAutoFollowPatterns

**Reproduction line:**
```
./gradlew ':x-pack:plugin:ccr:qa:multi-cluster:follow-cluster' --tests "org.elasticsearch.xpack.ccr.AutoFollowIT.testAutoFollowPatterns" -Dtests.seed=50A0B430B1BC44DE -Dtests.locale=sr-BA -Dtests.timezone=Pacific/Auckland -Druntime.java=8
```

**Applicable branches:**
7.17

**Reproduces locally?:**
No

**Failure history:**
https://gradle-enterprise.elastic.co/scans/tests?tests.container=org.elasticsearch.xpack.ccr.AutoFollowIT&tests.test=testAutoFollowPatterns

**Failure excerpt:**
```
java.lang.AssertionError: Unexpected number of followed indices [{"took":10,"timed_out":false,"_shards":{"total":2,"successful":2,"skipped":0,"failed":0},"hits":{"total":{"value":34,"relation":"eq"},"max_score":2.75246,"hits":[{"_index":".monitoring-es-7-2022.11.28","_type":"_doc","_id":"cVLbv4QBur_2UWL7Sj95","_score":2.75246,"_source":{"cluster_uuid":"MJcQUR1jTqqfK7SYlC2tbw","timestamp":"2022-11-28T20:08:50.533Z","interval_ms":10000,"type":"ccr_auto_follow_stats","source_node":{"uuid":"Ql0gc-E9Si-p7FWiiH_TWw","host":"127.0.0.1","transport_address":"127.0.0.1:43959","ip":"127.0.0.1","name":"follow-cluster-0","timestamp":"2022-11-28T20:08:50.357Z"},"ccr_auto_follow_stats":{"number_of_failed_follow_indices":0,"number_of_failed_remote_cluster_state_requests":0,"number_of_successful_follow_indices":0,"recent_auto_follow_errors":[],"auto_followed_clusters":[]}}},{"_index":".monitoring-es-7-2022.11.28","_type":"_doc","_id":"eVLbv4QBur_2UWL7cT-p","_score":2.75246,"_source":{"cluster_uuid":"MJcQUR1jTqqfK7SYlC2tbw","timestamp":"2022-11-28T20:09:00.547Z","interval_ms":10000,"type":"ccr_auto_follow_stats","source_node":{"uuid":"Ql0gc-E9Si-p7FWiiH_TWw","host":"127.0.0.1","transport_address":"127.0.0.1:43959","ip":"127.0.0.1","name":"follow-cluster-0","timestamp":"2022-11-28T20:09:00.358Z"},"ccr_auto_follow_stats":{"number_of_failed_follow_indices":0,"number_of_failed_remote_cluster_state_requests":0,"number_of_successful_follow_indices":0,"recent_auto_follow_errors":[],"auto_followed_clusters":[]}}},{"_index":".monitoring-es-7-2022.11.28","_type":"_doc","_id":"gVLbv4QBur_2UWL7mD-9","_score":2.75246,"_source":{"cluster_uuid":"MJcQUR1jTqqfK7SYlC2tbw","timestamp":"2022-11-28T20:09:10.563Z","interval_ms":10000,"type":"ccr_auto_follow_stats","source_node":{"uuid":"Ql0gc-E9Si-p7FWiiH_TWw","host":"127.0.0.1","transport_address":"127.0.0.1:43959","ip":"127.0.0.1","name":"follow-cluster-0","timestamp":"2022-11-28T20:09:10.358Z"},"ccr_auto_follow_stats":{"number_of_failed_follow_indices":0,"number_of_failed_remote_cluster_state_requests":0,"number_of_successful_follow_indices":0,"recent_auto_follow_errors":[],"auto_followed_clusters":[]}}},{"_index":".monitoring-es-7-2022.11.28","_type":"_doc","_id":"oFLcv4QBur_2UWL7DT_d","_score":2.75246,"_source":{"cluster_uuid":"MJcQUR1jTqqfK7SYlC2tbw","timestamp":"2022-11-28T20:09:40.538Z","interval_ms":10000,"type":"ccr_auto_follow_stats","source_node":{"uuid":"Ql0gc-E9Si-p7FWiiH_TWw","host":"127.0.0.1","transport_address":"127.0.0.1:43959","ip":"127.0.0.1","name":"follow-cluster-0","timestamp":"2022-11-28T20:09:40.359Z"},"ccr_auto_follow_stats":{"number_of_failed_follow_indices":0,"number_of_failed_remote_cluster_state_requests":0,"number_of_successful_follow_indices":0,"recent_auto_follow_errors":[],"auto_followed_clusters":[]}}},{"_index":".monitoring-es-7-2022.11.28","_type":"_doc","_id":"i1Lbv4QBur_2UWL7vz-6","_score":2.75246,"_source":{"cluster_uuid":"MJcQUR1jTqqfK7SYlC2tbw","timestamp":"2022-11-28T20:09:20.535Z","interval_ms":10000,"type":"ccr_auto_follow_stats","source_node":{"uuid":"Ql0gc-E9Si-p7FWiiH_TWw","host":"127.0.0.1","transport_address":"127.0.0.1:43959","ip":"127.0.0.1","name":"follow-cluster-0","timestamp":"2022-11-28T20:09:20.358Z"},"ccr_auto_follow_stats":{"number_of_failed_follow_indices":0,"number_of_failed_remote_cluster_state_requests":0,"number_of_successful_follow_indices":0,"recent_auto_follow_errors":[],"auto_followed_clusters":[]}}},{"_index":".monitoring-es-7-2022.11.28","_type":"_doc","_id":"YVLav4QBur_2UWL7_D9Y","_score":2.75246,"_source":{"cluster_uuid":"MJcQUR1jTqqfK7SYlC2tbw","timestamp":"2022-11-28T20:08:30.505Z","interval_ms":10000,"type":"ccr_auto_follow_stats","source_node":{"uuid":"Ql0gc-E9Si-p7FWiiH_TWw","host":"127.0.0.1","transport_address":"127.0.0.1:43959","ip":"127.0.0.1","name":"follow-cluster-0","timestamp":"2022-11-28T20:08:30.353Z"},"ccr_auto_follow_stats":{"number_of_failed_follow_indices":0,"number_of_failed_remote_cluster_state_requests":0,"number_of_successful_follow_indices":0,"recent_auto_follow_errors":[],"auto_followed_clusters":[]}}},{"_index":".monitoring-es-7-2022.11.28","_type":"_doc","_id":"aVLbv4QBur_2UWL7Iz9S","_score":2.75246,"_source":{"cluster_uuid":"MJcQUR1jTqqfK7SYlC2tbw","timestamp":"2022-11-28T20:08:40.503Z","interval_ms":10000,"type":"ccr_auto_follow_stats","source_node":{"uuid":"Ql0gc-E9Si-p7FWiiH_TWw","host":"127.0.0.1","transport_address":"127.0.0.1:43959","ip":"127.0.0.1","name":"follow-cluster-0","timestamp":"2022-11-28T20:08:40.354Z"},"ccr_auto_follow_stats":{"number_of_failed_follow_indices":0,"number_of_failed_remote_cluster_state_requests":0,"number_of_successful_follow_indices":0,"recent_auto_follow_errors":[],"auto_followed_clusters":[]}}},{"_index":".monitoring-es-7-2022.11.28","_type":"_doc","_id":"l1Lbv4QBur_2UWL75j_l","_score":2.75246,"_source":{"cluster_uuid":"MJcQUR1jTqqfK7SYlC2tbw","timestamp":"2022-11-28T20:09:30.503Z","interval_ms":10000,"type":"ccr_auto_follow_stats","source_node":{"uuid":"Ql0gc-E9Si-p7FWiiH_TWw","host":"127.0.0.1","transport_address":"127.0.0.1:43959","ip":"127.0.0.1","name":"follow-cluster-0","timestamp":"2022-11-28T20:09:30.359Z"},"ccr_auto_follow_stats":{"number_of_failed_follow_indices":0,"number_of_failed_remote_cluster_state_requests":0,"number_of_successful_follow_indices":0,"recent_auto_follow_errors":[],"auto_followed_clusters":[]}}},{"_index":".monitoring-es-7-2022.11.28","_type":"_doc","_id":"WVLav4QBur_2UWL71j8T","_score":2.75246,"_source":{"cluster_uuid":"MJcQUR1jTqqfK7SYlC2tbw","timestamp":"2022-11-28T20:08:20.659Z","interval_ms":10000,"type":"ccr_auto_follow_stats","source_node":{"uuid":"Ql0gc-E9Si-p7FWiiH_TWw","host":"127.0.0.1","transport_address":"127.0.0.1:43959","ip":"127.0.0.1","name":"follow-cluster-0","timestamp":"2022-11-28T20:08:20.353Z"},"ccr_auto_follow_stats":{"number_of_failed_follow_indices":0,"number_of_failed_remote_cluster_state_requests":0,"number_of_successful_follow_indices":0,"recent_auto_follow_errors":[],"auto_followed_clusters":[]}}},{"_index":".monitoring-es-7-2022.11.28","_type":"_doc","_id":"UVLav4QBur_2UWL7uj-y","_score":2.75246,"_source":{"cluster_uuid":"MJcQUR1jTqqfK7SYlC2tbw","timestamp":"2022-11-28T20:08:11.054Z","interval_ms":10000,"type":"ccr_auto_follow_stats","source_node":{"uuid":"Ql0gc-E9Si-p7FWiiH_TWw","host":"127.0.0.1","transport_address":"127.0.0.1:43959","ip":"127.0.0.1","name":"follow-cluster-0","timestamp":"2022-11-28T20:08:10.353Z"},"ccr_auto_follow_stats":{"number_of_failed_follow_indices":0,"number_of_failed_remote_cluster_state_requests":0,"number_of_successful_follow_indices":0,"recent_auto_follow_errors":[],"auto_followed_clusters":[]}}}]}}]
Expected: a value equal to or greater than <1>
     but: <0> was less than <1>

  at __randomizedtesting.SeedInfo.seed([50A0B430B1BC44DE:F9070A1B7952D55A]:0)
  at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:18)
  at org.junit.Assert.assertThat(Assert.java:956)
  at org.elasticsearch.xpack.ccr.ESCCRRestTestCase.verifyAutoFollowMonitoring(ESCCRRestTestCase.java:247)
  at org.elasticsearch.test.ESTestCase.assertBusy(ESTestCase.java:1141)
  at org.elasticsearch.xpack.ccr.AutoFollowIT.assertLongBusy(AutoFollowIT.java:905)
  at org.elasticsearch.xpack.ccr.AutoFollowIT.testAutoFollowPatterns(AutoFollowIT.java:176)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethodAccessorImpl.java:-2)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:498)
  at com.carrotsearch.randomizedtesting.RandomizedRunner.invoke(RandomizedRunner.java:1758)
  at com.carrotsearch.randomizedtesting.RandomizedRunner$8.evaluate(RandomizedRunner.java:946)
  at com.carrotsearch.randomizedtesting.RandomizedRunner$9.evaluate(RandomizedRunner.java:982)
  at com.carrotsearch.randomizedtesting.RandomizedRunner$10.evaluate(RandomizedRunner.java:996)
  at com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
  at org.apache.lucene.util.TestRuleSetupTeardownChained$1.evaluate(TestRuleSetupTeardownChained.java:49)
  at org.apache.lucene.util.AbstractBeforeAfterRule$1.evaluate(AbstractBeforeAfterRule.java:45)
  at org.apache.lucene.util.TestRuleThreadAndTestName$1.evaluate(TestRuleThreadAndTestName.java:48)
  at org.apache.lucene.util.TestRuleIgnoreAfterMaxFailures$1.evaluate(TestRuleIgnoreAfterMaxFailures.java:64)
  at org.apache.lucene.util.TestRuleMarkFailure$1.evaluate(TestRuleMarkFailure.java:47)
  at com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
  at com.carrotsearch.randomizedtesting.ThreadLeakControl$StatementRunner.run(ThreadLeakControl.java:390)
  at com.carrotsearch.randomizedtesting.ThreadLeakControl.forkTimeoutingTask(ThreadLeakControl.java:843)
  at com.carrotsearch.randomizedtesting.ThreadLeakControl$3.evaluate(ThreadLeakControl.java:490)
  at com.carrotsearch.randomizedtesting.RandomizedRunner.runSingleTest(RandomizedRunner.java:955)
  at com.carrotsearch.randomizedtesting.RandomizedRunner$5.evaluate(RandomizedRunner.java:840)
  at com.carrotsearch.randomizedtesting.RandomizedRunner$6.evaluate(RandomizedRunner.java:891)
  at com.carrotsearch.randomizedtesting.RandomizedRunner$7.evaluate(RandomizedRunner.java:902)
  at org.apache.lucene.util.AbstractBeforeAfterRule$1.evaluate(AbstractBeforeAfterRule.java:45)
  at com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
  at org.apache.lucene.util.TestRuleStoreClassName$1.evaluate(TestRuleStoreClassName.java:41)
  at com.carrotsearch.randomizedtesting.rules.NoShadowingOrOverridesOnMethodsRule$1.evaluate(NoShadowingOrOverridesOnMethodsRule.java:40)
  at com.carrotsearch.randomizedtesting.rules.NoShadowingOrOverridesOnMethodsRule$1.evaluate(NoShadowingOrOverridesOnMethodsRule.java:40)
  at com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
  at com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
  at com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
  at org.apache.lucene.util.TestRuleAssertionsRequired$1.evaluate(TestRuleAssertionsRequired.java:53)
  at org.apache.lucene.util.TestRuleMarkFailure$1.evaluate(TestRuleMarkFailure.java:47)
  at org.apache.lucene.util.TestRuleIgnoreAfterMaxFailures$1.evaluate(TestRuleIgnoreAfterMaxFailures.java:64)
  at org.apache.lucene.util.TestRuleIgnoreTestSuites$1.evaluate(TestRuleIgnoreTestSuites.java:54)
  at com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
  at com.carrotsearch.randomizedtesting.ThreadLeakControl$StatementRunner.run(ThreadLeakControl.java:390)
  at com.carrotsearch.randomizedtesting.ThreadLeakControl.lambda$forkTimeoutingTask$0(ThreadLeakControl.java:850)
  at java.lang.Thread.run(Thread.java:748)

```
x-pack/plugin/ccr/qa/src/main/java/org/elasticsearch/xpack/ccr/ESCCRRestTestCase.java
}
    protected static void verifyDocuments(final RestClient client, final String index, final int expectedNumDocs) throws IOException {
        final Request request = new Request("GET", "/" + index + "/_search");
        request.addParameter(TOTAL_HITS_AS_INT_PARAM, "true");
        Map<String, ?> response = toMap(client.performRequest(request));
        int numDocs = (int) XContentMapValues.extractValue("hits.total", response);
        assertThat(index, numDocs, equalTo(expectedNumDocs));
    }
    protected static void verifyCcrMonitoring(final String expectedLeaderIndex, final String expectedFollowerIndex) throws IOException {
        Request request = new Request("GET", "/.monitoring-*/_search");
        request.setJsonEntity(String.format(Locale.ROOT, """
            {"query": {"term": {"ccr_stats.leader_index": "%s"}}}
            """, expectedLeaderIndex));
        Map<String, ?> response;
        try {
            response = toMap(adminClient().performRequest(request));
        } catch (ResponseException e) {
            throw new AssertionError("error while searching", e);
        }
        int followerMaxSeqNo = 0;
        int followerMappingVersion = 0;
        int followerSettingsVersion = 0;
        int followerAliasesVersion = 0;
        List<?> hits = (List<?>) XContentMapValues.extractValue("hits.hits", response);
        assertThat(hits.size(), greaterThanOrEqualTo(1));
        for (int i = 0; i < hits.size(); i++) {
            Map<?, ?> hit = (Map<?, ?>) hits.get(i);
            String leaderIndex = (String) XContentMapValues.extractValue("_source.ccr_stats.leader_index", hit);
            assertThat(leaderIndex, endsWith(expectedLeaderIndex));
            final String followerIndex = (String) XContentMapValues.extractValue("_source.ccr_stats.follower_index", hit);