diff --git a/server/src/main/java/org/elasticsearch/index/engine/InternalEngine.java b/server/src/main/java/org/elasticsearch/index/engine/InternalEngine.java index e835faae96f66..ec0ad1ed79f0d 100644 --- a/server/src/main/java/org/elasticsearch/index/engine/InternalEngine.java +++ b/server/src/main/java/org/elasticsearch/index/engine/InternalEngine.java @@ -2709,8 +2709,7 @@ private IndexWriterConfig getIndexWriterConfig() { // always configure soft-deletes field so an engine with soft-deletes disabled can open a Lucene index with soft-deletes. iwc.setSoftDeletesField(Lucene.SOFT_DELETES_FIELD); mergePolicy = new RecoverySourcePruneMergePolicy( - engineConfig.getMapperService().mappingLookup().isSourceSynthetic() - && engineConfig.getIndexSettings().isRecoverySourceSyntheticEnabled() ? null : SourceFieldMapper.RECOVERY_SOURCE_NAME, + useSyntheticSourceForRecovery() ? null : SourceFieldMapper.RECOVERY_SOURCE_NAME, SourceFieldMapper.RECOVERY_SOURCE_SIZE_NAME, engineConfig.getIndexSettings().getMode() == IndexMode.TIME_SERIES, softDeletesPolicy::getRetentionQuery, @@ -2755,6 +2754,13 @@ private IndexWriterConfig getIndexWriterConfig() { return iwc; } + private boolean useSyntheticSourceForRecovery() { + return engineConfig.getMapperService() != null + && engineConfig.getMapperService().mappingLookup().isSourceSynthetic() + && engineConfig.getIndexSettings().isRecoverySourceSyntheticEnabled(); + + } + /** A listener that warms the segments if needed when acquiring a new reader */ static final class RefreshWarmerListener implements BiConsumer { private final Warmer warmer; @@ -3156,8 +3162,7 @@ public Translog.Snapshot newChangesSnapshot( Searcher searcher = acquireSearcher(source, SearcherScope.INTERNAL); try { final Translog.Snapshot snapshot; - if (engineConfig.getMapperService().mappingLookup().isSourceSynthetic() - && engineConfig.getIndexSettings().isRecoverySourceSyntheticEnabled()) { + if (useSyntheticSourceForRecovery()) { snapshot = new LuceneSyntheticSourceChangesSnapshot( engineConfig.getMapperService().mappingLookup(), searcher,