diff --git a/src/main/kotlin/org/opensearch/replication/ReplicationPlugin.kt b/src/main/kotlin/org/opensearch/replication/ReplicationPlugin.kt index 3fa602b0..53c77866 100644 --- a/src/main/kotlin/org/opensearch/replication/ReplicationPlugin.kt +++ b/src/main/kotlin/org/opensearch/replication/ReplicationPlugin.kt @@ -143,6 +143,9 @@ import org.opensearch.watcher.ResourceWatcherService import java.util.Optional import java.util.function.Supplier +import org.opensearch.index.engine.NRTReplicationEngine + + @OpenForTesting internal class ReplicationPlugin : Plugin(), ActionPlugin, PersistentTaskPlugin, RepositoryPlugin, EnginePlugin { @@ -359,7 +362,14 @@ internal class ReplicationPlugin : Plugin(), ActionPlugin, PersistentTaskPlugin, override fun getEngineFactory(indexSettings: IndexSettings): Optional { return if (indexSettings.settings.get(REPLICATED_INDEX_SETTING.key) != null) { - Optional.of(EngineFactory { config -> ReplicationEngine(config) }) + Optional.of(EngineFactory { config -> + // Use NRTSegmentReplicationEngine for SEGMENT replication type indices replica shards + if (config.isReadOnlyReplica) { + NRTReplicationEngine(config) + } else { + ReplicationEngine(config) + } + }) } else { Optional.empty() }