diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ClearIndicesCacheRequest.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ClearIndicesCacheRequest.java index 00bea9aa6ac..51343d9de02 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ClearIndicesCacheRequest.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ClearIndicesCacheRequest.java @@ -31,7 +31,10 @@ import java.io.IOException; */ public class ClearIndicesCacheRequest extends BroadcastOperationRequest { - private boolean filterCache = true; + private boolean filterCache = false; + private boolean fieldDataCache = false; + private boolean idCache = false; + private boolean bloomCache = false; ClearIndicesCacheRequest() { } @@ -62,21 +65,51 @@ public class ClearIndicesCacheRequest extends BroadcastOperationRequest { return filterCache; } - /** - * Should the filter cache be cleared or not. Defaults to true. - */ public ClearIndicesCacheRequest filterCache(boolean filterCache) { this.filterCache = filterCache; return this; } + public boolean fieldDataCache() { + return this.fieldDataCache; + } + + public ClearIndicesCacheRequest fieldDataCache(boolean fieldDataCache) { + this.fieldDataCache = fieldDataCache; + return this; + } + + public boolean idCache() { + return this.idCache; + } + + public ClearIndicesCacheRequest idCache(boolean idCache) { + this.idCache = idCache; + return this; + } + + public boolean bloomCache() { + return this.bloomCache; + } + + public ClearIndicesCacheRequest bloomCache(boolean bloomCache) { + this.bloomCache = bloomCache; + return this; + } + public void readFrom(StreamInput in) throws IOException { super.readFrom(in); filterCache = in.readBoolean(); + fieldDataCache = in.readBoolean(); + idCache = in.readBoolean(); + bloomCache = in.readBoolean(); } public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); out.writeBoolean(filterCache); + out.writeBoolean(fieldDataCache); + out.writeBoolean(idCache); + out.writeBoolean(bloomCache); } } \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ShardClearIndicesCacheRequest.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ShardClearIndicesCacheRequest.java index d94254e76db..78509995efd 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ShardClearIndicesCacheRequest.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ShardClearIndicesCacheRequest.java @@ -30,7 +30,10 @@ import java.io.IOException; */ class ShardClearIndicesCacheRequest extends BroadcastShardOperationRequest { - private boolean filterCache = true; + private boolean filterCache = false; + private boolean fieldDataCache = false; + private boolean idCache = false; + private boolean bloomCache = false; ShardClearIndicesCacheRequest() { } @@ -38,12 +41,27 @@ class ShardClearIndicesCacheRequest extends BroadcastShardOperationRequest { public ShardClearIndicesCacheRequest(String index, int shardId, ClearIndicesCacheRequest request) { super(index, shardId); filterCache = request.filterCache(); + fieldDataCache = request.fieldDataCache(); + idCache = request.idCache(); + bloomCache = request.bloomCache(); } public boolean filterCache() { return filterCache; } + public boolean fieldDataCache() { + return this.fieldDataCache; + } + + public boolean idCache() { + return this.idCache; + } + + public boolean bloomCache() { + return this.bloomCache; + } + public ShardClearIndicesCacheRequest waitForOperations(boolean waitForOperations) { this.filterCache = waitForOperations; return this; @@ -52,10 +70,16 @@ class ShardClearIndicesCacheRequest extends BroadcastShardOperationRequest { @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); filterCache = in.readBoolean(); + fieldDataCache = in.readBoolean(); + idCache = in.readBoolean(); + bloomCache = in.readBoolean(); } @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); out.writeBoolean(filterCache); + out.writeBoolean(fieldDataCache); + out.writeBoolean(idCache); + out.writeBoolean(bloomCache); } } \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/TransportClearIndicesCacheAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/TransportClearIndicesCacheAction.java index 9df922f53e2..67509e385e6 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/TransportClearIndicesCacheAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/TransportClearIndicesCacheAction.java @@ -111,10 +111,30 @@ public class TransportClearIndicesCacheAction extends TransportBroadcastOperatio } @Override protected ShardClearIndicesCacheResponse shardOperation(ShardClearIndicesCacheRequest request) throws ElasticSearchException { - // TODO we can optimize to go to a single node where the index exists IndexService service = indicesService.indexService(request.index()); if (service != null) { - service.cache().clear(); + // we always clear the query cache + service.cache().queryParserCache().clear(); + boolean clearedAtLeastOne = false; + if (request.filterCache()) { + clearedAtLeastOne = true; + service.cache().filter().clear(); + } + if (request.fieldDataCache()) { + clearedAtLeastOne = true; + service.cache().fieldData().clear(); + } + if (request.idCache()) { + clearedAtLeastOne = true; + service.cache().idCache().clear(); + } + if (request.bloomCache()) { + clearedAtLeastOne = true; + service.cache().bloomCache().clear(); + } + if (!clearedAtLeastOne) { + service.cache().clear(); + } } return new ShardClearIndicesCacheResponse(request.index(), request.shardId()); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/action/admin/indices/cache/clear/ClearIndicesCacheRequestBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/action/admin/indices/cache/clear/ClearIndicesCacheRequestBuilder.java index 3e70a5727cd..6ba23b53723 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/action/admin/indices/cache/clear/ClearIndicesCacheRequestBuilder.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/action/admin/indices/cache/clear/ClearIndicesCacheRequestBuilder.java @@ -40,14 +40,26 @@ public class ClearIndicesCacheRequestBuilder extends BaseIndicesRequestBuildertrue. - */ public ClearIndicesCacheRequestBuilder setFilterCache(boolean filterCache) { request.filterCache(filterCache); return this; } + public ClearIndicesCacheRequestBuilder setFieldDataCache(boolean fieldDataCache) { + request.fieldDataCache(fieldDataCache); + return this; + } + + public ClearIndicesCacheRequestBuilder setIdCache(boolean idCache) { + request.idCache(idCache); + return this; + } + + public ClearIndicesCacheRequestBuilder setBloomCache(boolean bloomCache) { + request.bloomCache(bloomCache); + return this; + } + /** * Should the listener be called on a separate thread if needed. */ diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/cache/clear/RestClearIndicesCacheAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/cache/clear/RestClearIndicesCacheAction.java index 60bb9e9c5ad..25843e97e7b 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/cache/clear/RestClearIndicesCacheAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/cache/clear/RestClearIndicesCacheAction.java @@ -54,7 +54,10 @@ public class RestClearIndicesCacheAction extends BaseRestHandler { @Override public void handleRequest(final RestRequest request, final RestChannel channel) { ClearIndicesCacheRequest clearIndicesCacheRequest = new ClearIndicesCacheRequest(RestActions.splitIndices(request.param("index"))); try { - clearIndicesCacheRequest.filterCache(request.paramAsBoolean("filter_cache", clearIndicesCacheRequest.filterCache())); + clearIndicesCacheRequest.filterCache(request.paramAsBoolean("filter", clearIndicesCacheRequest.filterCache())); + clearIndicesCacheRequest.fieldDataCache(request.paramAsBoolean("field_data", clearIndicesCacheRequest.fieldDataCache())); + clearIndicesCacheRequest.idCache(request.paramAsBoolean("id", clearIndicesCacheRequest.idCache())); + clearIndicesCacheRequest.bloomCache(request.paramAsBoolean("bloom", clearIndicesCacheRequest.bloomCache())); // we just send back a response, no need to fork a listener clearIndicesCacheRequest.listenerThreaded(false);