diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/ShardChangesIT.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/ShardChangesIT.java index e19087e767b53..14ab1b90aa639 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/ShardChangesIT.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/ShardChangesIT.java @@ -355,7 +355,7 @@ public void afterBulk(long executionId, BulkRequest request, Throwable failure) assertSameDocCount("index1", "index2"); assertTotalNumberOfOptimizedIndexing(resolveIndex("index2"), numberOfShards, - client().prepareSearch("index2").get().getHits().totalHits); + client().prepareSearch("index1").get().getHits().totalHits); unfollowIndex("index2"); assertMaxSeqNoOfUpdatesIsTransferred(resolveIndex("index1"), resolveIndex("index2"), numberOfShards); } @@ -915,7 +915,7 @@ private void assertTotalNumberOfOptimizedIndexing(Index followerIndex, int numbe for (String node : internalCluster().nodesInclude(followerIndex.getName())) { IndicesService indicesService = internalCluster().getInstance(IndicesService.class, node); IndexShard shard = indicesService.getShardOrNull(new ShardId(followerIndex, shardId)); - if (shard != null) { + if (shard != null && shard.routingEntry().primary()) { try { FollowingEngine engine = ((FollowingEngine) IndexShardTestCase.getEngine(shard)); numOfOptimizedOps[shardId] = engine.getNumberOfOptimizedIndexing();