diff --git a/server/src/main/java/org/elasticsearch/index/engine/LuceneSyntheticSourceChangesSnapshot.java b/server/src/main/java/org/elasticsearch/index/engine/LuceneSyntheticSourceChangesSnapshot.java index 2bc517745f7e2..55b648ccdd6e3 100644 --- a/server/src/main/java/org/elasticsearch/index/engine/LuceneSyntheticSourceChangesSnapshot.java +++ b/server/src/main/java/org/elasticsearch/index/engine/LuceneSyntheticSourceChangesSnapshot.java @@ -83,7 +83,8 @@ public LuceneSyntheticSourceChangesSnapshot( this.maxMemorySizeInBytes = maxMemorySizeInBytes; this.sourceLoader = mappingLookup.newSourceLoader(SourceFieldMetrics.NOOP); Set storedFields = sourceLoader.requiredStoredFields(); - this.storedFieldLoader = StoredFieldLoader.create(mappingLookup.isSourceSynthetic() == false, storedFields); + assert mappingLookup.isSourceSynthetic() : "synthetic source must be enabled for proper functionality."; + this.storedFieldLoader = StoredFieldLoader.create(false, storedFields); this.lastSeenSeqNo = fromSeqNo - 1; } diff --git a/server/src/main/java/org/elasticsearch/index/engine/SearchBasedChangesSnapshot.java b/server/src/main/java/org/elasticsearch/index/engine/SearchBasedChangesSnapshot.java index e95aea24910e0..191125c59705e 100644 --- a/server/src/main/java/org/elasticsearch/index/engine/SearchBasedChangesSnapshot.java +++ b/server/src/main/java/org/elasticsearch/index/engine/SearchBasedChangesSnapshot.java @@ -83,6 +83,13 @@ protected SearchBasedChangesSnapshot( throw new IllegalArgumentException("Search_batch_size must be positive [" + searchBatchSize + "]"); } + final AtomicBoolean closed = new AtomicBoolean(); + this.onClose = () -> { + if (closed.compareAndSet(false, true)) { + IOUtils.close(engineSearcher); + } + }; + this.indexVersionCreated = indexVersionCreated; this.fromSeqNo = fromSeqNo; this.toSeqNo = toSeqNo; @@ -91,13 +98,6 @@ protected SearchBasedChangesSnapshot( this.indexSearcher = newIndexSearcher(engineSearcher); this.indexSearcher.setQueryCache(null); - final AtomicBoolean closed = new AtomicBoolean(); - this.onClose = () -> { - if (closed.compareAndSet(false, true)) { - IOUtils.close(engineSearcher); - } - }; - long requestingSize = (toSeqNo - fromSeqNo == Long.MAX_VALUE) ? Long.MAX_VALUE : (toSeqNo - fromSeqNo + 1L); this.searchBatchSize = (int) Math.min(requestingSize, searchBatchSize);