diff --git a/src/main/java/org/elasticsearch/index/cache/id/simple/SimpleIdCache.java b/src/main/java/org/elasticsearch/index/cache/id/simple/SimpleIdCache.java index fa6242de3ad..f01322b02f9 100644 --- a/src/main/java/org/elasticsearch/index/cache/id/simple/SimpleIdCache.java +++ b/src/main/java/org/elasticsearch/index/cache/id/simple/SimpleIdCache.java @@ -47,11 +47,13 @@ import java.util.concurrent.ConcurrentMap; public class SimpleIdCache extends AbstractIndexComponent implements IdCache, SegmentReader.CoreClosedListener { private final ConcurrentMap idReaders; + private final boolean reuse; @Inject public SimpleIdCache(Index index, @IndexSettings Settings indexSettings) { super(index, indexSettings); idReaders = ConcurrentCollections.newConcurrentMap(); + this.reuse = componentSettings.getAsBoolean("reuse", false); } @Override @@ -207,12 +209,15 @@ public class SimpleIdCache extends AbstractIndexComponent implements IdCache, Se private HashedBytesArray checkIfCanReuse(Map> builders, HashedBytesArray idAsBytes) { HashedBytesArray finalIdAsBytes; // go over and see if we can reuse this id - for (SimpleIdReaderCache idReaderCache : idReaders.values()) { - finalIdAsBytes = idReaderCache.canReuse(idAsBytes); - if (finalIdAsBytes != null) { - return finalIdAsBytes; + if (reuse) { + for (SimpleIdReaderCache idReaderCache : idReaders.values()) { + finalIdAsBytes = idReaderCache.canReuse(idAsBytes); + if (finalIdAsBytes != null) { + return finalIdAsBytes; + } } } + // even if we don't enable reuse, at least check on the current "live" builders that we are handling for (Map map : builders.values()) { for (TypeBuilder typeBuilder : map.values()) { finalIdAsBytes = typeBuilder.canReuse(idAsBytes);