diff --git a/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ClearIndicesCacheRequestBuilder.java b/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ClearIndicesCacheRequestBuilder.java index 5fa2eaa74b9..c4903f6d870 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ClearIndicesCacheRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ClearIndicesCacheRequestBuilder.java @@ -21,6 +21,7 @@ package org.elasticsearch.action.admin.indices.cache.clear; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.indices.support.BaseIndicesRequestBuilder; +import org.elasticsearch.action.support.IgnoreIndices; import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading; import org.elasticsearch.client.IndicesAdminClient; @@ -79,6 +80,14 @@ public class ClearIndicesCacheRequestBuilder extends BaseIndicesRequestBuilder listener) { client.clearCache(request, listener); diff --git a/src/main/java/org/elasticsearch/action/admin/indices/flush/FlushRequestBuilder.java b/src/main/java/org/elasticsearch/action/admin/indices/flush/FlushRequestBuilder.java index db773010eed..89f70f220dd 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/flush/FlushRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/flush/FlushRequestBuilder.java @@ -21,6 +21,7 @@ package org.elasticsearch.action.admin.indices.flush; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.indices.support.BaseIndicesRequestBuilder; +import org.elasticsearch.action.support.IgnoreIndices; import org.elasticsearch.client.IndicesAdminClient; /** @@ -47,6 +48,14 @@ public class FlushRequestBuilder extends BaseIndicesRequestBuilder listener) { client.flush(request, listener); diff --git a/src/main/java/org/elasticsearch/action/admin/indices/gateway/snapshot/GatewaySnapshotRequestBuilder.java b/src/main/java/org/elasticsearch/action/admin/indices/gateway/snapshot/GatewaySnapshotRequestBuilder.java index 8e5759433e9..f41ea74f838 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/gateway/snapshot/GatewaySnapshotRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/gateway/snapshot/GatewaySnapshotRequestBuilder.java @@ -21,6 +21,7 @@ package org.elasticsearch.action.admin.indices.gateway.snapshot; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.indices.support.BaseIndicesRequestBuilder; +import org.elasticsearch.action.support.IgnoreIndices; import org.elasticsearch.client.IndicesAdminClient; /** @@ -37,6 +38,14 @@ public class GatewaySnapshotRequestBuilder extends BaseIndicesRequestBuilder listener) { client.gatewaySnapshot(request, listener); diff --git a/src/main/java/org/elasticsearch/action/admin/indices/optimize/OptimizeRequestBuilder.java b/src/main/java/org/elasticsearch/action/admin/indices/optimize/OptimizeRequestBuilder.java index ed8b4d3ba18..24a6286dc05 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/optimize/OptimizeRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/optimize/OptimizeRequestBuilder.java @@ -21,6 +21,7 @@ package org.elasticsearch.action.admin.indices.optimize; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.indices.support.BaseIndicesRequestBuilder; +import org.elasticsearch.action.support.IgnoreIndices; import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading; import org.elasticsearch.client.IndicesAdminClient; @@ -103,6 +104,14 @@ public class OptimizeRequestBuilder extends BaseIndicesRequestBuilder listener) { client.optimize(request, listener); diff --git a/src/main/java/org/elasticsearch/action/admin/indices/refresh/RefreshRequestBuilder.java b/src/main/java/org/elasticsearch/action/admin/indices/refresh/RefreshRequestBuilder.java index 228964cd85d..87f4379f509 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/refresh/RefreshRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/refresh/RefreshRequestBuilder.java @@ -21,6 +21,7 @@ package org.elasticsearch.action.admin.indices.refresh; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.indices.support.BaseIndicesRequestBuilder; +import org.elasticsearch.action.support.IgnoreIndices; import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading; import org.elasticsearch.client.IndicesAdminClient; @@ -61,6 +62,14 @@ public class RefreshRequestBuilder extends BaseIndicesRequestBuilder listener) { client.refresh(request, listener); diff --git a/src/main/java/org/elasticsearch/action/admin/indices/segments/IndicesSegmentsRequestBuilder.java b/src/main/java/org/elasticsearch/action/admin/indices/segments/IndicesSegmentsRequestBuilder.java index 6a511f2e725..6fa10cb94ce 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/segments/IndicesSegmentsRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/segments/IndicesSegmentsRequestBuilder.java @@ -21,6 +21,7 @@ package org.elasticsearch.action.admin.indices.segments; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.indices.support.BaseIndicesRequestBuilder; +import org.elasticsearch.action.support.IgnoreIndices; import org.elasticsearch.client.IndicesAdminClient; /** @@ -37,6 +38,14 @@ public class IndicesSegmentsRequestBuilder extends BaseIndicesRequestBuilder listener) { client.segments(request, listener); diff --git a/src/main/java/org/elasticsearch/action/admin/indices/stats/IndicesStatsRequestBuilder.java b/src/main/java/org/elasticsearch/action/admin/indices/stats/IndicesStatsRequestBuilder.java index a1ad93589ed..751014b3f03 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/stats/IndicesStatsRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/stats/IndicesStatsRequestBuilder.java @@ -21,6 +21,7 @@ package org.elasticsearch.action.admin.indices.stats; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.indices.support.BaseIndicesRequestBuilder; +import org.elasticsearch.action.support.IgnoreIndices; import org.elasticsearch.client.IndicesAdminClient; /** @@ -121,6 +122,14 @@ public class IndicesStatsRequestBuilder extends BaseIndicesRequestBuilder listener) { client.stats(request, listener); diff --git a/src/main/java/org/elasticsearch/action/admin/indices/status/IndicesStatusRequestBuilder.java b/src/main/java/org/elasticsearch/action/admin/indices/status/IndicesStatusRequestBuilder.java index 4540e4a7fd7..a85c83808b8 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/status/IndicesStatusRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/status/IndicesStatusRequestBuilder.java @@ -21,6 +21,7 @@ package org.elasticsearch.action.admin.indices.status; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.indices.support.BaseIndicesRequestBuilder; +import org.elasticsearch.action.support.IgnoreIndices; import org.elasticsearch.client.IndicesAdminClient; /** @@ -56,6 +57,14 @@ public class IndicesStatusRequestBuilder extends BaseIndicesRequestBuilder listener) { client.status(request, listener); diff --git a/src/main/java/org/elasticsearch/action/admin/indices/validate/query/ValidateQueryRequestBuilder.java b/src/main/java/org/elasticsearch/action/admin/indices/validate/query/ValidateQueryRequestBuilder.java index 6e8ad05115c..69e6e245c3d 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/validate/query/ValidateQueryRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/validate/query/ValidateQueryRequestBuilder.java @@ -2,6 +2,7 @@ package org.elasticsearch.action.admin.indices.validate.query; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.indices.support.BaseIndicesRequestBuilder; +import org.elasticsearch.action.support.IgnoreIndices; import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading; import org.elasticsearch.client.IndicesAdminClient; import org.elasticsearch.common.bytes.BytesReference; @@ -97,6 +98,14 @@ public class ValidateQueryRequestBuilder extends BaseIndicesRequestBuilder listener) { client.validateQuery(request, listener); diff --git a/src/main/java/org/elasticsearch/action/count/CountRequestBuilder.java b/src/main/java/org/elasticsearch/action/count/CountRequestBuilder.java index cf56c25644d..5c195cc06f0 100644 --- a/src/main/java/org/elasticsearch/action/count/CountRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/count/CountRequestBuilder.java @@ -21,6 +21,7 @@ package org.elasticsearch.action.count; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.support.BaseRequestBuilder; +import org.elasticsearch.action.support.IgnoreIndices; import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading; import org.elasticsearch.client.Client; import org.elasticsearch.common.bytes.BytesReference; @@ -140,6 +141,14 @@ public class CountRequestBuilder extends BaseRequestBuilder listener) { client.count(request, listener); diff --git a/src/main/java/org/elasticsearch/action/search/MultiSearchRequest.java b/src/main/java/org/elasticsearch/action/search/MultiSearchRequest.java index 2e144caa7d0..4eaaa03c72b 100644 --- a/src/main/java/org/elasticsearch/action/search/MultiSearchRequest.java +++ b/src/main/java/org/elasticsearch/action/search/MultiSearchRequest.java @@ -22,6 +22,7 @@ package org.elasticsearch.action.search; import com.google.common.collect.Lists; import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionRequestValidationException; +import org.elasticsearch.action.support.IgnoreIndices; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesArray; @@ -45,6 +46,7 @@ public class MultiSearchRequest implements ActionRequest { private List requests = Lists.newArrayList(); private boolean listenerThreaded = false; + private IgnoreIndices ignoreIndices = IgnoreIndices.DEFAULT; /** * Add a search request to execute. Note, the order is important, the search response will be returned in the @@ -66,11 +68,11 @@ public class MultiSearchRequest implements ActionRequest { public MultiSearchRequest add(byte[] data, int from, int length, boolean contentUnsafe, @Nullable String[] indices, @Nullable String[] types, @Nullable String searchType) throws Exception { - return add(new BytesArray(data, from, length), contentUnsafe, indices, types, searchType); + return add(new BytesArray(data, from, length), contentUnsafe, indices, types, searchType, IgnoreIndices.NONE); } public MultiSearchRequest add(BytesReference data, boolean contentUnsafe, - @Nullable String[] indices, @Nullable String[] types, @Nullable String searchType) throws Exception { + @Nullable String[] indices, @Nullable String[] types, @Nullable String searchType, IgnoreIndices ignoreIndices) throws Exception { XContent xContent = XContentFactory.xContent(data); int from = 0; int length = data.length(); @@ -87,6 +89,9 @@ public class MultiSearchRequest implements ActionRequest { } SearchRequest searchRequest = new SearchRequest(indices); + if (ignoreIndices != null) { + searchRequest.ignoreIndices(ignoreIndices); + } if (types != null && types.length > 0) { searchRequest.types(types); } @@ -117,6 +122,8 @@ public class MultiSearchRequest implements ActionRequest { searchRequest.routing(parser.text()); } else if ("query_hint".equals(currentFieldName) || "queryHint".equals(currentFieldName)) { searchRequest.queryHint(parser.text()); + } else if ("ignore_indices".equals(currentFieldName) || "ignoreIndices".equals(currentFieldName)) { + searchRequest.ignoreIndices(IgnoreIndices.fromString(parser.text())); } } } @@ -187,6 +194,15 @@ public class MultiSearchRequest implements ActionRequest { return this; } + public IgnoreIndices ignoreIndices() { + return ignoreIndices; + } + + public MultiSearchRequest ignoreIndices(IgnoreIndices ignoreIndices) { + this.ignoreIndices = ignoreIndices; + return this; + } + @Override public void readFrom(StreamInput in) throws IOException { int size = in.readVInt(); diff --git a/src/main/java/org/elasticsearch/action/search/MultiSearchRequestBuilder.java b/src/main/java/org/elasticsearch/action/search/MultiSearchRequestBuilder.java index acd60156f37..daa285b50fd 100644 --- a/src/main/java/org/elasticsearch/action/search/MultiSearchRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/search/MultiSearchRequestBuilder.java @@ -21,6 +21,7 @@ package org.elasticsearch.action.search; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.support.BaseRequestBuilder; +import org.elasticsearch.action.support.IgnoreIndices; import org.elasticsearch.client.Client; /** @@ -35,8 +36,15 @@ public class MultiSearchRequestBuilder extends BaseRequestBuilder listener) { client.multiSearch(request, listener); diff --git a/src/main/java/org/elasticsearch/action/search/SearchRequest.java b/src/main/java/org/elasticsearch/action/search/SearchRequest.java index 3e31f549318..f841db1e3a1 100644 --- a/src/main/java/org/elasticsearch/action/search/SearchRequest.java +++ b/src/main/java/org/elasticsearch/action/search/SearchRequest.java @@ -23,6 +23,7 @@ import org.elasticsearch.ElasticSearchGenerationException; import org.elasticsearch.ElasticSearchIllegalArgumentException; import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionRequestValidationException; +import org.elasticsearch.action.support.IgnoreIndices; import org.elasticsearch.client.Requests; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Strings; @@ -83,6 +84,8 @@ public class SearchRequest implements ActionRequest { private boolean listenerThreaded = false; private SearchOperationThreading operationThreading = SearchOperationThreading.THREAD_PER_SHARD; + private IgnoreIndices ignoreIndices = IgnoreIndices.DEFAULT; + public SearchRequest() { } @@ -179,6 +182,15 @@ public class SearchRequest implements ActionRequest { return operationThreading(SearchOperationThreading.fromString(operationThreading, this.operationThreading)); } + public IgnoreIndices ignoreIndices() { + return ignoreIndices; + } + + public SearchRequest ignoreIndices(IgnoreIndices ignoreIndices) { + this.ignoreIndices = ignoreIndices; + return this; + } + /** * The document types to execute the search against. Defaults to be executed against * all types. @@ -496,6 +508,7 @@ public class SearchRequest implements ActionRequest { types[i] = in.readUTF(); } } + ignoreIndices = IgnoreIndices.fromId(in.readByte()); } @Override @@ -539,5 +552,6 @@ public class SearchRequest implements ActionRequest { for (String type : types) { out.writeUTF(type); } + out.writeByte(ignoreIndices.id()); } } diff --git a/src/main/java/org/elasticsearch/action/search/SearchRequestBuilder.java b/src/main/java/org/elasticsearch/action/search/SearchRequestBuilder.java index 5390c05b2cb..01eaf35b330 100644 --- a/src/main/java/org/elasticsearch/action/search/SearchRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/search/SearchRequestBuilder.java @@ -22,6 +22,7 @@ package org.elasticsearch.action.search; import org.elasticsearch.ElasticSearchIllegalArgumentException; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.support.BaseRequestBuilder; +import org.elasticsearch.action.support.IgnoreIndices; import org.elasticsearch.client.Client; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.bytes.BytesReference; @@ -183,6 +184,14 @@ public class SearchRequestBuilder extends BaseRequestBuilder> routingMap = clusterState.metaData().resolveSearchRouting(searchRequest.routing(), searchRequest.indices()); int shardCount = clusterService.operationRouting().searchShardsCount(clusterState, searchRequest.indices(), concreteIndices, searchRequest.queryHint(), routingMap, searchRequest.preference()); if (shardCount == 1) { diff --git a/src/main/java/org/elasticsearch/action/search/type/TransportSearchTypeAction.java b/src/main/java/org/elasticsearch/action/search/type/TransportSearchTypeAction.java index e8ef8cb443b..b803f74cca1 100644 --- a/src/main/java/org/elasticsearch/action/search/type/TransportSearchTypeAction.java +++ b/src/main/java/org/elasticsearch/action/search/type/TransportSearchTypeAction.java @@ -108,7 +108,7 @@ public abstract class TransportSearchTypeAction extends TransportAction { } public Map> resolveSearchRouting(@Nullable String routing, String aliasOrIndex) { - return resolveSearchRouting(routing, convertFromWildcards(new String[]{aliasOrIndex}, true, true)); + return resolveSearchRouting(routing, convertFromWildcards(new String[]{aliasOrIndex}, true, IgnoreIndices.MISSING)); } public Map> resolveSearchRouting(@Nullable String routing, String[] aliasesOrIndices) { @@ -350,7 +351,7 @@ public class MetaData implements Iterable { return resolveSearchRoutingAllIndices(routing); } - aliasesOrIndices = convertFromWildcards(aliasesOrIndices, true, true); + aliasesOrIndices = convertFromWildcards(aliasesOrIndices, true, IgnoreIndices.MISSING); if (aliasesOrIndices.length == 1) { return resolveSearchRoutingSingleValue(routing, aliasesOrIndices[0]); @@ -493,24 +494,24 @@ public class MetaData implements Iterable { * Translates the provided indices (possibly aliased) into actual indices. */ public String[] concreteIndices(String[] indices) throws IndexMissingException { - return concreteIndices(indices, false, false); + return concreteIndices(indices, IgnoreIndices.NONE, false); } /** * Translates the provided indices (possibly aliased) into actual indices. */ public String[] concreteIndicesIgnoreMissing(String[] indices) { - return concreteIndices(indices, true, false); + return concreteIndices(indices, IgnoreIndices.MISSING, false); } /** * Translates the provided indices (possibly aliased) into actual indices. */ - public String[] concreteIndices(String[] aliasesOrIndices, boolean ignoreMissing, boolean allOnlyOpen) throws IndexMissingException { + public String[] concreteIndices(String[] aliasesOrIndices, IgnoreIndices ignoreIndices, boolean allOnlyOpen) throws IndexMissingException { if (isAllIndices(aliasesOrIndices)) { return allOnlyOpen ? concreteAllOpenIndices() : concreteAllIndices(); } - aliasesOrIndices = convertFromWildcards(aliasesOrIndices, allOnlyOpen, ignoreMissing); + aliasesOrIndices = convertFromWildcards(aliasesOrIndices, allOnlyOpen, ignoreIndices); // optimize for single element index (common case) if (aliasesOrIndices.length == 1) { String aliasOrIndex = aliasesOrIndices[0]; @@ -520,11 +521,10 @@ public class MetaData implements Iterable { } String[] actualLst = aliasAndIndexToIndexMap.get(aliasOrIndex); if (actualLst == null) { - if (!ignoreMissing) { - throw new IndexMissingException(new Index(aliasOrIndex)); - } else { + if (ignoreIndices == IgnoreIndices.MISSING) { return Strings.EMPTY_ARRAY; } + throw new IndexMissingException(new Index(aliasOrIndex)); } else { return actualLst; } @@ -547,7 +547,7 @@ public class MetaData implements Iterable { for (String index : aliasesOrIndices) { String[] actualLst = aliasAndIndexToIndexMap.get(index); if (actualLst == null) { - if (!ignoreMissing) { + if (ignoreIndices != IgnoreIndices.MISSING) { throw new IndexMissingException(new Index(index)); } } else { @@ -575,7 +575,7 @@ public class MetaData implements Iterable { return lst[0]; } - public String[] convertFromWildcards(String[] aliasesOrIndices, boolean wildcardOnlyOpen, boolean ignoreMissing) { + public String[] convertFromWildcards(String[] aliasesOrIndices, boolean wildcardOnlyOpen, IgnoreIndices ignoreIndices) { Set result = null; for (int i = 0; i < aliasesOrIndices.length; i++) { String aliasOrIndex = aliasesOrIndices[i]; @@ -598,7 +598,7 @@ public class MetaData implements Iterable { aliasOrIndex = aliasOrIndex.substring(1); } if (!Regex.isSimpleMatchPattern(aliasOrIndex)) { - if (!ignoreMissing && !aliasAndIndexToIndexMap.containsKey(aliasOrIndex)) { + if (ignoreIndices != IgnoreIndices.MISSING && !aliasAndIndexToIndexMap.containsKey(aliasOrIndex)) { throw new IndexMissingException(new Index(aliasOrIndex)); } if (result != null) { @@ -637,7 +637,7 @@ public class MetaData implements Iterable { } } } - if (!found && !ignoreMissing) { + if (!found && ignoreIndices != IgnoreIndices.MISSING) { throw new IndexMissingException(new Index(aliasOrIndex)); } } diff --git a/src/main/java/org/elasticsearch/index/query/IndicesFilterParser.java b/src/main/java/org/elasticsearch/index/query/IndicesFilterParser.java index e8b5b05432b..aa29d61e58d 100644 --- a/src/main/java/org/elasticsearch/index/query/IndicesFilterParser.java +++ b/src/main/java/org/elasticsearch/index/query/IndicesFilterParser.java @@ -21,6 +21,7 @@ package org.elasticsearch.index.query; import com.google.common.collect.Sets; import org.apache.lucene.search.Filter; +import org.elasticsearch.action.support.IgnoreIndices; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.Nullable; @@ -115,7 +116,7 @@ public class IndicesFilterParser implements FilterParser { String[] concreteIndices = indices.toArray(new String[indices.size()]); if (clusterService != null) { MetaData metaData = clusterService.state().metaData(); - concreteIndices = metaData.concreteIndices(indices.toArray(new String[indices.size()]), true, true); + concreteIndices = metaData.concreteIndices(indices.toArray(new String[indices.size()]), IgnoreIndices.MISSING, true); } for (String index : concreteIndices) { diff --git a/src/main/java/org/elasticsearch/index/query/IndicesQueryParser.java b/src/main/java/org/elasticsearch/index/query/IndicesQueryParser.java index 048101e9137..071200af2cb 100644 --- a/src/main/java/org/elasticsearch/index/query/IndicesQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/IndicesQueryParser.java @@ -21,6 +21,7 @@ package org.elasticsearch.index.query; import com.google.common.collect.Sets; import org.apache.lucene.search.Query; +import org.elasticsearch.action.support.IgnoreIndices; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.Nullable; @@ -115,7 +116,7 @@ public class IndicesQueryParser implements QueryParser { String[] concreteIndices = indices.toArray(new String[indices.size()]); if (clusterService != null) { MetaData metaData = clusterService.state().metaData(); - concreteIndices = metaData.concreteIndices(indices.toArray(new String[indices.size()]), true, true); + concreteIndices = metaData.concreteIndices(indices.toArray(new String[indices.size()]), IgnoreIndices.MISSING, true); } for (String index : concreteIndices) { diff --git a/src/main/java/org/elasticsearch/rest/action/admin/indices/cache/clear/RestClearIndicesCacheAction.java b/src/main/java/org/elasticsearch/rest/action/admin/indices/cache/clear/RestClearIndicesCacheAction.java index 1eb647ba44e..d4f26d1ee47 100644 --- a/src/main/java/org/elasticsearch/rest/action/admin/indices/cache/clear/RestClearIndicesCacheAction.java +++ b/src/main/java/org/elasticsearch/rest/action/admin/indices/cache/clear/RestClearIndicesCacheAction.java @@ -22,6 +22,7 @@ package org.elasticsearch.rest.action.admin.indices.cache.clear; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest; import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheResponse; +import org.elasticsearch.action.support.IgnoreIndices; import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading; import org.elasticsearch.client.Client; import org.elasticsearch.common.inject.Inject; @@ -58,6 +59,7 @@ public class RestClearIndicesCacheAction extends BaseRestHandler { public void handleRequest(final RestRequest request, final RestChannel channel) { ClearIndicesCacheRequest clearIndicesCacheRequest = new ClearIndicesCacheRequest(RestActions.splitIndices(request.param("index"))); clearIndicesCacheRequest.listenerThreaded(false); + clearIndicesCacheRequest.ignoreIndices(IgnoreIndices.fromString(request.param("ignore_indices"))); try { clearIndicesCacheRequest.filterCache(request.paramAsBoolean("filter", clearIndicesCacheRequest.filterCache())); clearIndicesCacheRequest.fieldDataCache(request.paramAsBoolean("field_data", clearIndicesCacheRequest.fieldDataCache())); diff --git a/src/main/java/org/elasticsearch/rest/action/admin/indices/flush/RestFlushAction.java b/src/main/java/org/elasticsearch/rest/action/admin/indices/flush/RestFlushAction.java index c7d75aba264..c387b298c5a 100644 --- a/src/main/java/org/elasticsearch/rest/action/admin/indices/flush/RestFlushAction.java +++ b/src/main/java/org/elasticsearch/rest/action/admin/indices/flush/RestFlushAction.java @@ -22,6 +22,7 @@ package org.elasticsearch.rest.action.admin.indices.flush; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.indices.flush.FlushRequest; import org.elasticsearch.action.admin.indices.flush.FlushResponse; +import org.elasticsearch.action.support.IgnoreIndices; import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading; import org.elasticsearch.client.Client; import org.elasticsearch.common.inject.Inject; @@ -57,6 +58,7 @@ public class RestFlushAction extends BaseRestHandler { public void handleRequest(final RestRequest request, final RestChannel channel) { FlushRequest flushRequest = new FlushRequest(RestActions.splitIndices(request.param("index"))); flushRequest.listenerThreaded(false); + flushRequest.ignoreIndices(IgnoreIndices.fromString(request.param("ignore_indices"))); BroadcastOperationThreading operationThreading = BroadcastOperationThreading.fromString(request.param("operationThreading"), BroadcastOperationThreading.SINGLE_THREAD); if (operationThreading == BroadcastOperationThreading.NO_THREADS) { // since we don't spawn, don't allow no_threads, but change it to a single thread diff --git a/src/main/java/org/elasticsearch/rest/action/admin/indices/gateway/snapshot/RestGatewaySnapshotAction.java b/src/main/java/org/elasticsearch/rest/action/admin/indices/gateway/snapshot/RestGatewaySnapshotAction.java index 9dce9e1b76f..82bbb2f7952 100644 --- a/src/main/java/org/elasticsearch/rest/action/admin/indices/gateway/snapshot/RestGatewaySnapshotAction.java +++ b/src/main/java/org/elasticsearch/rest/action/admin/indices/gateway/snapshot/RestGatewaySnapshotAction.java @@ -22,6 +22,7 @@ package org.elasticsearch.rest.action.admin.indices.gateway.snapshot; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.indices.gateway.snapshot.GatewaySnapshotRequest; import org.elasticsearch.action.admin.indices.gateway.snapshot.GatewaySnapshotResponse; +import org.elasticsearch.action.support.IgnoreIndices; import org.elasticsearch.client.Client; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; @@ -52,6 +53,7 @@ public class RestGatewaySnapshotAction extends BaseRestHandler { public void handleRequest(final RestRequest request, final RestChannel channel) { GatewaySnapshotRequest gatewaySnapshotRequest = new GatewaySnapshotRequest(RestActions.splitIndices(request.param("index"))); gatewaySnapshotRequest.listenerThreaded(false); + gatewaySnapshotRequest.ignoreIndices(IgnoreIndices.fromString(request.param("ignore_indices"))); client.admin().indices().gatewaySnapshot(gatewaySnapshotRequest, new ActionListener() { @Override public void onResponse(GatewaySnapshotResponse response) { diff --git a/src/main/java/org/elasticsearch/rest/action/admin/indices/optimize/RestOptimizeAction.java b/src/main/java/org/elasticsearch/rest/action/admin/indices/optimize/RestOptimizeAction.java index bfeee9a260c..1efcb69357e 100644 --- a/src/main/java/org/elasticsearch/rest/action/admin/indices/optimize/RestOptimizeAction.java +++ b/src/main/java/org/elasticsearch/rest/action/admin/indices/optimize/RestOptimizeAction.java @@ -22,6 +22,7 @@ package org.elasticsearch.rest.action.admin.indices.optimize; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.indices.optimize.OptimizeRequest; import org.elasticsearch.action.admin.indices.optimize.OptimizeResponse; +import org.elasticsearch.action.support.IgnoreIndices; import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading; import org.elasticsearch.client.Client; import org.elasticsearch.common.inject.Inject; @@ -58,6 +59,7 @@ public class RestOptimizeAction extends BaseRestHandler { public void handleRequest(final RestRequest request, final RestChannel channel) { OptimizeRequest optimizeRequest = new OptimizeRequest(RestActions.splitIndices(request.param("index"))); optimizeRequest.listenerThreaded(false); + optimizeRequest.ignoreIndices(IgnoreIndices.fromString(request.param("ignore_indices"))); try { optimizeRequest.waitForMerge(request.paramAsBoolean("wait_for_merge", optimizeRequest.waitForMerge())); optimizeRequest.maxNumSegments(request.paramAsInt("max_num_segments", optimizeRequest.maxNumSegments())); diff --git a/src/main/java/org/elasticsearch/rest/action/admin/indices/refresh/RestRefreshAction.java b/src/main/java/org/elasticsearch/rest/action/admin/indices/refresh/RestRefreshAction.java index 8b4b3a68361..ac26e12202c 100644 --- a/src/main/java/org/elasticsearch/rest/action/admin/indices/refresh/RestRefreshAction.java +++ b/src/main/java/org/elasticsearch/rest/action/admin/indices/refresh/RestRefreshAction.java @@ -22,6 +22,7 @@ package org.elasticsearch.rest.action.admin.indices.refresh; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.indices.refresh.RefreshRequest; import org.elasticsearch.action.admin.indices.refresh.RefreshResponse; +import org.elasticsearch.action.support.IgnoreIndices; import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading; import org.elasticsearch.client.Client; import org.elasticsearch.common.inject.Inject; @@ -57,6 +58,7 @@ public class RestRefreshAction extends BaseRestHandler { public void handleRequest(final RestRequest request, final RestChannel channel) { RefreshRequest refreshRequest = new RefreshRequest(RestActions.splitIndices(request.param("index"))); refreshRequest.listenerThreaded(false); + refreshRequest.ignoreIndices(IgnoreIndices.fromString(request.param("ignore_indices"))); BroadcastOperationThreading operationThreading = BroadcastOperationThreading.fromString(request.param("operation_threading"), BroadcastOperationThreading.SINGLE_THREAD); if (operationThreading == BroadcastOperationThreading.NO_THREADS) { // since we don't spawn, don't allow no_threads, but change it to a single thread diff --git a/src/main/java/org/elasticsearch/rest/action/admin/indices/segments/RestIndicesSegmentsAction.java b/src/main/java/org/elasticsearch/rest/action/admin/indices/segments/RestIndicesSegmentsAction.java index 21c0417232f..9defc531cbd 100644 --- a/src/main/java/org/elasticsearch/rest/action/admin/indices/segments/RestIndicesSegmentsAction.java +++ b/src/main/java/org/elasticsearch/rest/action/admin/indices/segments/RestIndicesSegmentsAction.java @@ -22,6 +22,7 @@ package org.elasticsearch.rest.action.admin.indices.segments; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.indices.segments.IndicesSegmentResponse; import org.elasticsearch.action.admin.indices.segments.IndicesSegmentsRequest; +import org.elasticsearch.action.support.IgnoreIndices; import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading; import org.elasticsearch.client.Client; import org.elasticsearch.common.inject.Inject; @@ -52,6 +53,7 @@ public class RestIndicesSegmentsAction extends BaseRestHandler { public void handleRequest(final RestRequest request, final RestChannel channel) { IndicesSegmentsRequest indicesSegmentsRequest = new IndicesSegmentsRequest(splitIndices(request.param("index"))); indicesSegmentsRequest.listenerThreaded(false); + indicesSegmentsRequest.ignoreIndices(IgnoreIndices.fromString(request.param("ignore_indices"))); BroadcastOperationThreading operationThreading = BroadcastOperationThreading.fromString(request.param("operation_threading"), BroadcastOperationThreading.SINGLE_THREAD); if (operationThreading == BroadcastOperationThreading.NO_THREADS) { // since we don't spawn, don't allow no_threads, but change it to a single thread diff --git a/src/main/java/org/elasticsearch/rest/action/admin/indices/stats/RestIndicesStatsAction.java b/src/main/java/org/elasticsearch/rest/action/admin/indices/stats/RestIndicesStatsAction.java index 8b84f866931..8507bc6b262 100644 --- a/src/main/java/org/elasticsearch/rest/action/admin/indices/stats/RestIndicesStatsAction.java +++ b/src/main/java/org/elasticsearch/rest/action/admin/indices/stats/RestIndicesStatsAction.java @@ -22,6 +22,7 @@ package org.elasticsearch.rest.action.admin.indices.stats; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.indices.stats.IndicesStats; import org.elasticsearch.action.admin.indices.stats.IndicesStatsRequest; +import org.elasticsearch.action.support.IgnoreIndices; import org.elasticsearch.client.Client; import org.elasticsearch.common.Strings; import org.elasticsearch.common.inject.Inject; @@ -82,6 +83,7 @@ public class RestIndicesStatsAction extends BaseRestHandler { public void handleRequest(final RestRequest request, final RestChannel channel) { IndicesStatsRequest indicesStatsRequest = new IndicesStatsRequest(); indicesStatsRequest.listenerThreaded(false); + indicesStatsRequest.ignoreIndices(IgnoreIndices.fromString(request.param("ignore_indices"))); boolean clear = request.paramAsBoolean("clear", false); if (clear) { indicesStatsRequest.clear(); diff --git a/src/main/java/org/elasticsearch/rest/action/admin/indices/status/RestIndicesStatusAction.java b/src/main/java/org/elasticsearch/rest/action/admin/indices/status/RestIndicesStatusAction.java index 5c671ccde03..d09e1a04259 100644 --- a/src/main/java/org/elasticsearch/rest/action/admin/indices/status/RestIndicesStatusAction.java +++ b/src/main/java/org/elasticsearch/rest/action/admin/indices/status/RestIndicesStatusAction.java @@ -22,6 +22,7 @@ package org.elasticsearch.rest.action.admin.indices.status; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.indices.status.IndicesStatusRequest; import org.elasticsearch.action.admin.indices.status.IndicesStatusResponse; +import org.elasticsearch.action.support.IgnoreIndices; import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading; import org.elasticsearch.client.Client; import org.elasticsearch.common.inject.Inject; @@ -59,6 +60,7 @@ public class RestIndicesStatusAction extends BaseRestHandler { public void handleRequest(final RestRequest request, final RestChannel channel) { IndicesStatusRequest indicesStatusRequest = new IndicesStatusRequest(splitIndices(request.param("index"))); indicesStatusRequest.listenerThreaded(false); + indicesStatusRequest.ignoreIndices(IgnoreIndices.fromString(request.param("ignore_indices"))); indicesStatusRequest.recovery(request.paramAsBoolean("recovery", indicesStatusRequest.recovery())); indicesStatusRequest.snapshot(request.paramAsBoolean("snapshot", indicesStatusRequest.snapshot())); BroadcastOperationThreading operationThreading = BroadcastOperationThreading.fromString(request.param("operation_threading"), BroadcastOperationThreading.SINGLE_THREAD); diff --git a/src/main/java/org/elasticsearch/rest/action/admin/indices/validate/query/RestValidateQueryAction.java b/src/main/java/org/elasticsearch/rest/action/admin/indices/validate/query/RestValidateQueryAction.java index bc2ec49c7a2..db713ca605e 100644 --- a/src/main/java/org/elasticsearch/rest/action/admin/indices/validate/query/RestValidateQueryAction.java +++ b/src/main/java/org/elasticsearch/rest/action/admin/indices/validate/query/RestValidateQueryAction.java @@ -23,6 +23,7 @@ import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.indices.validate.query.QueryExplanation; import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest; import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryResponse; +import org.elasticsearch.action.support.IgnoreIndices; import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading; import org.elasticsearch.client.Client; import org.elasticsearch.common.bytes.BytesReference; @@ -62,6 +63,7 @@ public class RestValidateQueryAction extends BaseRestHandler { public void handleRequest(final RestRequest request, final RestChannel channel) { ValidateQueryRequest validateQueryRequest = new ValidateQueryRequest(RestActions.splitIndices(request.param("index"))); validateQueryRequest.listenerThreaded(false); + validateQueryRequest.ignoreIndices(IgnoreIndices.fromString(request.param("ignore_indices"))); try { BroadcastOperationThreading operationThreading = BroadcastOperationThreading.fromString(request.param("operation_threading"), BroadcastOperationThreading.SINGLE_THREAD); if (operationThreading == BroadcastOperationThreading.NO_THREADS) { diff --git a/src/main/java/org/elasticsearch/rest/action/count/RestCountAction.java b/src/main/java/org/elasticsearch/rest/action/count/RestCountAction.java index 9e5155ddd9a..0dfc6a6dae7 100644 --- a/src/main/java/org/elasticsearch/rest/action/count/RestCountAction.java +++ b/src/main/java/org/elasticsearch/rest/action/count/RestCountAction.java @@ -22,6 +22,7 @@ package org.elasticsearch.rest.action.count; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.count.CountRequest; import org.elasticsearch.action.count.CountResponse; +import org.elasticsearch.action.support.IgnoreIndices; import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading; import org.elasticsearch.client.Client; import org.elasticsearch.common.bytes.BytesReference; @@ -61,6 +62,7 @@ public class RestCountAction extends BaseRestHandler { @Override public void handleRequest(final RestRequest request, final RestChannel channel) { CountRequest countRequest = new CountRequest(RestActions.splitIndices(request.param("index"))); + countRequest.ignoreIndices(IgnoreIndices.fromString(request.param("ignore_indices"))); countRequest.listenerThreaded(false); try { BroadcastOperationThreading operationThreading = BroadcastOperationThreading.fromString(request.param("operation_threading"), BroadcastOperationThreading.SINGLE_THREAD); diff --git a/src/main/java/org/elasticsearch/rest/action/search/RestMultiSearchAction.java b/src/main/java/org/elasticsearch/rest/action/search/RestMultiSearchAction.java index 56c5857d088..22614e2812c 100644 --- a/src/main/java/org/elasticsearch/rest/action/search/RestMultiSearchAction.java +++ b/src/main/java/org/elasticsearch/rest/action/search/RestMultiSearchAction.java @@ -22,6 +22,7 @@ package org.elasticsearch.rest.action.search; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.search.MultiSearchRequest; import org.elasticsearch.action.search.MultiSearchResponse; +import org.elasticsearch.action.support.IgnoreIndices; import org.elasticsearch.client.Client; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; @@ -60,9 +61,10 @@ public class RestMultiSearchAction extends BaseRestHandler { String[] indices = RestActions.splitIndices(request.param("index")); String[] types = RestActions.splitTypes(request.param("type")); + IgnoreIndices ignoreIndices = IgnoreIndices.fromString(request.param("ignore_indices")); try { - multiSearchRequest.add(request.content(), request.contentUnsafe(), indices, types, request.param("search_type")); + multiSearchRequest.add(request.content(), request.contentUnsafe(), indices, types, request.param("search_type"), ignoreIndices); } catch (Exception e) { try { XContentBuilder builder = restContentBuilder(request); diff --git a/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java b/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java index beb156c5315..a2a74b4cb1b 100644 --- a/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java +++ b/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java @@ -24,6 +24,7 @@ import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.search.SearchOperationThreading; import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchResponse; +import org.elasticsearch.action.support.IgnoreIndices; import org.elasticsearch.client.Client; import org.elasticsearch.common.Strings; import org.elasticsearch.common.inject.Inject; @@ -141,6 +142,7 @@ public class RestSearchAction extends BaseRestHandler { searchRequest.queryHint(request.param("query_hint")); searchRequest.routing(request.param("routing")); searchRequest.preference(request.param("preference")); + searchRequest.ignoreIndices(IgnoreIndices.fromString(request.param("ignore_indices"))); return searchRequest; } diff --git a/src/test/java/org/elasticsearch/test/integration/indices/IgnoreIndicesTests.java b/src/test/java/org/elasticsearch/test/integration/indices/IgnoreIndicesTests.java new file mode 100644 index 00000000000..60b527d9d24 --- /dev/null +++ b/src/test/java/org/elasticsearch/test/integration/indices/IgnoreIndicesTests.java @@ -0,0 +1,181 @@ +/* + * Licensed to ElasticSearch and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. ElasticSearch licenses this + * file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.test.integration.indices; + +import org.elasticsearch.action.search.MultiSearchResponse; +import org.elasticsearch.action.support.IgnoreIndices; +import org.elasticsearch.client.Client; +import org.elasticsearch.cluster.block.ClusterBlockException; +import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.indices.IndexMissingException; +import org.elasticsearch.test.integration.AbstractNodesTests; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.nullValue; +import static org.testng.Assert.fail; + +public class IgnoreIndicesTests extends AbstractNodesTests { + + private Client client; + + @BeforeClass + public void createNodes() throws Exception { + startNode("node1"); + client = client("node1"); + } + + @AfterClass + public void closeNodes() { + client.close(); + closeAllNodes(); + } + + @Test + public void testMissing() throws Exception { + client.admin().indices().prepareDelete().execute().actionGet(); + + client.admin().indices().prepareCreate("test1").execute().actionGet(); + client.admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet(); + try { + client.prepareSearch("test1", "test2").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet(); + fail("Exception should have been thrown."); + } catch (IndexMissingException e) {} + MultiSearchResponse multiSearchResponse = client.prepareMultiSearch().add( + client.prepareSearch("test1", "test2").setQuery(QueryBuilders.matchAllQuery()) + ).execute().actionGet(); + assertThat(multiSearchResponse.getResponses().length, equalTo(1)); + assertThat(multiSearchResponse.getResponses()[0].getResponse(), nullValue()); + try { + client.prepareCount("test1", "test2").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet(); + fail("Exception should have been thrown."); + } catch (IndexMissingException e) {} + try { + client.admin().indices().prepareClearCache("test1", "test2").execute().actionGet(); + fail("Exception should have been thrown."); + } catch (IndexMissingException e) {} + try { + client.admin().indices().prepareFlush("test1", "test2").execute().actionGet(); + fail("Exception should have been thrown."); + } catch (IndexMissingException e) {} + try { + client.admin().indices().prepareGatewaySnapshot("test1", "test2").execute().actionGet(); + fail("Exception should have been thrown."); + } catch (IndexMissingException e) {} + try { + client.admin().indices().prepareSegments("test1", "test2").execute().actionGet(); + fail("Exception should have been thrown."); + } catch (IndexMissingException e) {} + try { + client.admin().indices().prepareStats("test1", "test2").execute().actionGet(); + fail("Exception should have been thrown."); + } catch (IndexMissingException e) {} + try { + client.admin().indices().prepareStatus("test1", "test2").execute().actionGet(); + fail("Exception should have been thrown."); + } catch (IndexMissingException e) {} + try { + client.admin().indices().prepareOptimize("test1", "test2").execute().actionGet(); + fail("Exception should have been thrown."); + } catch (IndexMissingException e) {} + try { + client.admin().indices().prepareRefresh("test1", "test2").execute().actionGet(); + fail("Exception should have been thrown."); + } catch (IndexMissingException e) {} + try { + client.admin().indices().prepareValidateQuery("test1", "test2").execute().actionGet(); + fail("Exception should have been thrown."); + } catch (IndexMissingException e) {} + + client.prepareSearch("test1", "test2").setIgnoreIndices(IgnoreIndices.MISSING) + .setQuery(QueryBuilders.matchAllQuery()) + .execute().actionGet(); + multiSearchResponse = client.prepareMultiSearch().setIgnoreIndices(IgnoreIndices.MISSING).add( + client.prepareSearch("test1", "test2") + .setQuery(QueryBuilders.matchAllQuery()) + ).execute().actionGet(); + assertThat(multiSearchResponse.getResponses().length, equalTo(1)); + assertThat(multiSearchResponse.getResponses()[0].getResponse(), notNullValue()); + client.prepareCount("test1", "test2").setIgnoreIndices(IgnoreIndices.MISSING) + .setQuery(QueryBuilders.matchAllQuery()) + .execute().actionGet(); + client.admin().indices().prepareClearCache("test1", "test2").setIgnoreIndices(IgnoreIndices.MISSING) + .execute().actionGet(); + client.admin().indices().prepareFlush("test1", "test2").setIgnoreIndices(IgnoreIndices.MISSING) + .execute().actionGet(); + client.admin().indices().prepareGatewaySnapshot("test1", "test2").setIgnoreIndices(IgnoreIndices.MISSING) + .execute().actionGet(); + client.admin().indices().prepareSegments("test1", "test2").setIgnoreIndices(IgnoreIndices.MISSING) + .execute().actionGet(); + client.admin().indices().prepareStats("test1", "test2").setIgnoreIndices(IgnoreIndices.MISSING) + .execute().actionGet(); + client.admin().indices().prepareStatus("test1", "test2").setIgnoreIndices(IgnoreIndices.MISSING) + .execute().actionGet(); + client.admin().indices().prepareOptimize("test1", "test2").setIgnoreIndices(IgnoreIndices.MISSING) + .execute().actionGet(); + client.admin().indices().prepareRefresh("test1", "test2").setIgnoreIndices(IgnoreIndices.MISSING) + .execute().actionGet(); + client.admin().indices().prepareValidateQuery("test1", "test2").setIgnoreIndices(IgnoreIndices.MISSING) + .execute().actionGet(); + + client.admin().indices().prepareCreate("test2").execute().actionGet(); + client.admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet(); + client.prepareSearch("test1", "test2").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet(); + client.prepareCount("test1", "test2").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet(); + client.admin().indices().prepareClearCache("test1", "test2").execute().actionGet(); + client.admin().indices().prepareFlush("test1", "test2").execute().actionGet(); + client.admin().indices().prepareGatewaySnapshot("test1", "test2").execute().actionGet(); + client.admin().indices().prepareSegments("test1", "test2").execute().actionGet(); + client.admin().indices().prepareStats("test1", "test2").execute().actionGet(); + client.admin().indices().prepareStatus("test1", "test2").execute().actionGet(); + client.admin().indices().prepareOptimize("test1", "test2").execute().actionGet(); + client.admin().indices().prepareRefresh("test1", "test2").execute().actionGet(); + client.admin().indices().prepareValidateQuery("test1", "test2").execute().actionGet(); + } + + @Test + // For now don't handle closed indices + public void testClosed() throws Exception { + client.admin().indices().prepareDelete().execute().actionGet(); + + client.admin().indices().prepareCreate("test1").execute().actionGet(); + client.admin().indices().prepareCreate("test2").execute().actionGet(); + client.admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet(); + client.prepareSearch("test1", "test2").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet(); + + client.admin().indices().prepareClose("test2").execute().actionGet(); + client.admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet(); + try { + client.prepareSearch("test1", "test2").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet(); + fail("Exception should have been thrown"); + } catch (ClusterBlockException e) { + } + try { + client.prepareCount("test1", "test2").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet(); + fail("Exception should have been thrown"); + } catch (ClusterBlockException e) { + } + } + +} diff --git a/src/test/java/org/elasticsearch/test/unit/cluster/metadata/MetaDataTests.java b/src/test/java/org/elasticsearch/test/unit/cluster/metadata/MetaDataTests.java index 519c7616f72..2bd4295721f 100644 --- a/src/test/java/org/elasticsearch/test/unit/cluster/metadata/MetaDataTests.java +++ b/src/test/java/org/elasticsearch/test/unit/cluster/metadata/MetaDataTests.java @@ -19,6 +19,7 @@ package org.elasticsearch.test.unit.cluster.metadata; +import org.elasticsearch.action.support.IgnoreIndices; import org.elasticsearch.cluster.metadata.AliasMetaData; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.MetaData; @@ -41,12 +42,12 @@ public class MetaDataTests { .put(indexBuilder("testYYY")) .put(indexBuilder("kuku")); MetaData md = mdBuilder.build(); - assertThat(newHashSet(md.convertFromWildcards(new String[]{"testXXX"}, true, true)), equalTo(newHashSet("testXXX"))); - assertThat(newHashSet(md.convertFromWildcards(new String[]{"testXXX", "testYYY"}, true, true)), equalTo(newHashSet("testXXX", "testYYY"))); - assertThat(newHashSet(md.convertFromWildcards(new String[]{"testXXX", "ku*"}, true, true)), equalTo(newHashSet("testXXX", "kuku"))); - assertThat(newHashSet(md.convertFromWildcards(new String[]{"test*"}, true, true)), equalTo(newHashSet("testXXX", "testXYY", "testYYY"))); - assertThat(newHashSet(md.convertFromWildcards(new String[]{"testX*"}, true, true)), equalTo(newHashSet("testXXX", "testXYY"))); - assertThat(newHashSet(md.convertFromWildcards(new String[]{"testX*", "kuku"}, true, true)), equalTo(newHashSet("testXXX", "testXYY", "kuku"))); + assertThat(newHashSet(md.convertFromWildcards(new String[]{"testXXX"}, true, IgnoreIndices.MISSING)), equalTo(newHashSet("testXXX"))); + assertThat(newHashSet(md.convertFromWildcards(new String[]{"testXXX", "testYYY"}, true, IgnoreIndices.MISSING)), equalTo(newHashSet("testXXX", "testYYY"))); + assertThat(newHashSet(md.convertFromWildcards(new String[]{"testXXX", "ku*"}, true, IgnoreIndices.MISSING)), equalTo(newHashSet("testXXX", "kuku"))); + assertThat(newHashSet(md.convertFromWildcards(new String[]{"test*"}, true, IgnoreIndices.MISSING)), equalTo(newHashSet("testXXX", "testXYY", "testYYY"))); + assertThat(newHashSet(md.convertFromWildcards(new String[]{"testX*"}, true, IgnoreIndices.MISSING)), equalTo(newHashSet("testXXX", "testXYY"))); + assertThat(newHashSet(md.convertFromWildcards(new String[]{"testX*", "kuku"}, true, IgnoreIndices.MISSING)), equalTo(newHashSet("testXXX", "testXYY", "kuku"))); } @Test @@ -57,9 +58,9 @@ public class MetaDataTests { .put(indexBuilder("testYYY").putAlias(AliasMetaData.builder("alias3"))) .put(indexBuilder("kuku")); MetaData md = mdBuilder.build(); - assertThat(newHashSet(md.convertFromWildcards(new String[]{"testYY*", "alias*"}, true, true)), equalTo(newHashSet("alias1", "alias2", "alias3", "testYYY"))); - assertThat(newHashSet(md.convertFromWildcards(new String[]{"-kuku"}, true, true)), equalTo(newHashSet("testXXX", "testXYY", "testYYY"))); - assertThat(newHashSet(md.convertFromWildcards(new String[]{"+test*", "-testYYY"}, true, true)), equalTo(newHashSet("testXXX", "testXYY"))); + assertThat(newHashSet(md.convertFromWildcards(new String[]{"testYY*", "alias*"}, true, IgnoreIndices.MISSING)), equalTo(newHashSet("alias1", "alias2", "alias3", "testYYY"))); + assertThat(newHashSet(md.convertFromWildcards(new String[]{"-kuku"}, true, IgnoreIndices.MISSING)), equalTo(newHashSet("testXXX", "testXYY", "testYYY"))); + assertThat(newHashSet(md.convertFromWildcards(new String[]{"+test*", "-testYYY"}, true, IgnoreIndices.MISSING)), equalTo(newHashSet("testXXX", "testXYY"))); } private IndexMetaData.Builder indexBuilder(String index) {