diff --git a/server/src/main/java/org/opensearch/index/engine/InternalEngine.java b/server/src/main/java/org/opensearch/index/engine/InternalEngine.java index 705b5c1e85734..7859af0e22f64 100644 --- a/server/src/main/java/org/opensearch/index/engine/InternalEngine.java +++ b/server/src/main/java/org/opensearch/index/engine/InternalEngine.java @@ -2379,7 +2379,11 @@ protected SegmentInfos getLastCommittedSegmentInfos() { @Override protected final void writerSegmentStats(SegmentsStats stats) { stats.addVersionMapMemoryInBytes(versionMap.ramBytesUsed()); - stats.addIndexWriterMemoryInBytes(indexWriter.ramBytesUsed()); + long indexWriterMemoryInBytes = 0; + if (!(engineConfig.getIndexSettings().isSegrepEnabled() && engineConfig.isReadOnly())) { + indexWriterMemoryInBytes = indexWriter.ramBytesUsed(); + } + stats.addIndexWriterMemoryInBytes(indexWriterMemoryInBytes); stats.updateMaxUnsafeAutoIdTimestamp(maxUnsafeAutoIdTimestamp.get()); }