diff --git a/src/main/java/org/elasticsearch/index/fielddata/IndexFieldDataService.java b/src/main/java/org/elasticsearch/index/fielddata/IndexFieldDataService.java index 98d5d038763..815698c4aec 100644 --- a/src/main/java/org/elasticsearch/index/fielddata/IndexFieldDataService.java +++ b/src/main/java/org/elasticsearch/index/fielddata/IndexFieldDataService.java @@ -160,7 +160,9 @@ public class IndexFieldDataService extends AbstractIndexComponent implements Ind } IndexFieldDataCache cache; - String cacheType = type.getSettings().get("cache", indexSettings.get("index.fielddata.cache", "resident")); + // we default to node level cache, which in turn defaults to be unbounded + // this means changing the node level settings is simple, just set the bounds there + String cacheType = type.getSettings().get("cache", indexSettings.get("index.fielddata.cache", "node")); if ("resident".equals(cacheType)) { cache = new IndexFieldDataCache.Resident(index, fieldNames, type, this); } else if ("soft".equals(cacheType)) { diff --git a/src/main/java/org/elasticsearch/indices/fielddata/cache/IndicesFieldDataCache.java b/src/main/java/org/elasticsearch/indices/fielddata/cache/IndicesFieldDataCache.java index d610abd9797..18a930eb578 100644 --- a/src/main/java/org/elasticsearch/indices/fielddata/cache/IndicesFieldDataCache.java +++ b/src/main/java/org/elasticsearch/indices/fielddata/cache/IndicesFieldDataCache.java @@ -53,7 +53,7 @@ public class IndicesFieldDataCache extends AbstractComponent implements RemovalL @Inject public IndicesFieldDataCache(Settings settings) { super(settings); - this.size = componentSettings.get("size", "40%"); + this.size = componentSettings.get("size", "-1"); this.expire = componentSettings.getAsTime("expire", null); computeSizeInBytes(); buildCache(); @@ -62,17 +62,22 @@ public class IndicesFieldDataCache extends AbstractComponent implements RemovalL private void buildCache() { CacheBuilder cacheBuilder = CacheBuilder.newBuilder() .removalListener(this); - cacheBuilder.maximumWeight(sizeInBytes).weigher(new FieldDataWeigher()); + if (sizeInBytes > 0) { + cacheBuilder.maximumWeight(sizeInBytes).weigher(new FieldDataWeigher()); + } // defaults to 4, but this is a busy map for all indices, increase it a bit cacheBuilder.concurrencyLevel(16); - if (expire != null) { + if (expire != null && expire.millis() > 0) { cacheBuilder.expireAfterAccess(expire.millis(), TimeUnit.MILLISECONDS); } + logger.debug("using size [{}] [{}], expire [{}]", size, new ByteSizeValue(sizeInBytes), expire); cache = cacheBuilder.build(); } private void computeSizeInBytes() { - if (size.endsWith("%")) { + if (size.equals("-1")) { + sizeInBytes = -1; + } else if (size.endsWith("%")) { double percent = Double.parseDouble(size.substring(0, size.length() - 1)); sizeInBytes = (long) ((percent / 100) * JvmInfo.jvmInfo().getMem().getHeapMax().bytes()); } else {