Add ignore_indices option for search, multisearch, count and other Broadcast request. #2209

This commit is contained in:
Martijn van Groningen 2012-08-27 12:51:25 +02:00 committed by Shay Banon
parent 1d4aee6086
commit dea2de3304
36 changed files with 467 additions and 30 deletions

View File

@ -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<C
return this;
}
/**
* Specifies what type of requested indices to ignore. For example indices that don't exist.
*/
public ClearIndicesCacheRequestBuilder setIgnoreIndices(IgnoreIndices ignoreIndices) {
request().ignoreIndices(ignoreIndices);
return this;
}
@Override
protected void doExecute(ActionListener<ClearIndicesCacheResponse> listener) {
client.clearCache(request, listener);

View File

@ -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<FlushRequest,
return this;
}
/**
* Specifies what type of requested indices to ignore. For example indices that don't exist.
*/
public FlushRequestBuilder setIgnoreIndices(IgnoreIndices ignoreIndices) {
request().ignoreIndices(ignoreIndices);
return this;
}
@Override
protected void doExecute(ActionListener<FlushResponse> listener) {
client.flush(request, listener);

View File

@ -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<Gat
return this;
}
/**
* Specifies what type of requested indices to ignore. For example indices that don't exist.
*/
public GatewaySnapshotRequestBuilder setIgnoreIndices(IgnoreIndices ignoreIndices) {
request().ignoreIndices(ignoreIndices);
return this;
}
@Override
protected void doExecute(ActionListener<GatewaySnapshotResponse> listener) {
client.gatewaySnapshot(request, listener);

View File

@ -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<OptimizeRe
return this;
}
/**
* Specifies what type of requested indices to ignore. For example indices that don't exist.
*/
public OptimizeRequestBuilder setIgnoreIndices(IgnoreIndices ignoreIndices) {
request().ignoreIndices(ignoreIndices);
return this;
}
@Override
protected void doExecute(ActionListener<OptimizeResponse> listener) {
client.optimize(request, listener);

View File

@ -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<RefreshRequ
return this;
}
/**
* Specifies what type of requested indices to ignore. For example indices that don't exist.
*/
public RefreshRequestBuilder setIgnoreIndices(IgnoreIndices ignoreIndices) {
request().ignoreIndices(ignoreIndices);
return this;
}
@Override
protected void doExecute(ActionListener<RefreshResponse> listener) {
client.refresh(request, listener);

View File

@ -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<Ind
return this;
}
/**
* Specifies what type of requested indices to ignore. For example indices that don't exist.
*/
public IndicesSegmentsRequestBuilder setIgnoreIndices(IgnoreIndices ignoreIndices) {
request().ignoreIndices(ignoreIndices);
return this;
}
@Override
protected void doExecute(ActionListener<IndicesSegmentResponse> listener) {
client.segments(request, listener);

View File

@ -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<Indice
return this;
}
/**
* Specifies what type of requested indices to ignore. For example indices that don't exist.
*/
public IndicesStatsRequestBuilder setIgnoreIndices(IgnoreIndices ignoreIndices) {
request().ignoreIndices(ignoreIndices);
return this;
}
@Override
protected void doExecute(ActionListener<IndicesStats> listener) {
client.stats(request, listener);

View File

@ -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<Indic
return this;
}
/**
* Specifies what type of requested indices to ignore. For example indices that don't exist.
*/
public IndicesStatusRequestBuilder setIgnoreIndices(IgnoreIndices ignoreIndices) {
request().ignoreIndices(ignoreIndices);
return this;
}
@Override
protected void doExecute(ActionListener<IndicesStatusResponse> listener) {
client.status(request, listener);

View File

@ -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<Valid
return this;
}
/**
* Specifies what type of requested indices to ignore. For example indices that don't exist.
*/
public ValidateQueryRequestBuilder setIgnoreIndices(IgnoreIndices ignoreIndices) {
request().ignoreIndices(ignoreIndices);
return this;
}
@Override
protected void doExecute(ActionListener<ValidateQueryResponse> listener) {
client.validateQuery(request, listener);

View File

@ -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<CountRequest, CountR
return this;
}
/**
* Specifies what type of requested indices to ignore. For example indices that don't exist.
*/
public CountRequestBuilder setIgnoreIndices(IgnoreIndices ignoreIndices) {
request().ignoreIndices(ignoreIndices);
return this;
}
@Override
protected void doExecute(ActionListener<CountResponse> listener) {
client.count(request, listener);

View File

@ -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<SearchRequest> 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();

View File

@ -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<MultiSearchReq
/**
* Add a search request to execute. Note, the order is important, the search response will be returned in the
* same order as the search requests.
*
* If ignoreIndices has been set on the search request, then the ignoreIndices of the multi search request
* will not be used (if set).
*/
public MultiSearchRequestBuilder add(SearchRequest request) {
if (request.ignoreIndices() == IgnoreIndices.DEFAULT && request().ignoreIndices() != IgnoreIndices.DEFAULT) {
request.ignoreIndices(request().ignoreIndices());
}
super.request.add(request);
return this;
}
@ -46,10 +54,23 @@ public class MultiSearchRequestBuilder extends BaseRequestBuilder<MultiSearchReq
* same order as the search requests.
*/
public MultiSearchRequestBuilder add(SearchRequestBuilder request) {
if (request.request().ignoreIndices() == IgnoreIndices.DEFAULT && request().ignoreIndices() != IgnoreIndices.DEFAULT) {
request.request().ignoreIndices(request().ignoreIndices());
}
super.request.add(request);
return this;
}
/**
* Specifies what type of requested indices to ignore. For example indices that don't exist.
* Invoke this method before invoking {@link #add(SearchRequestBuilder)}.
*/
public MultiSearchRequestBuilder setIgnoreIndices(IgnoreIndices ignoreIndices) {
request().ignoreIndices(ignoreIndices);
return this;
}
@Override
protected void doExecute(ActionListener<MultiSearchResponse> listener) {
client.multiSearch(request, listener);

View File

@ -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());
}
}

View File

@ -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<SearchRequest, Sear
return this;
}
/**
* Specifies what type of requested indices to ignore. For example indices that don't exist.
*/
public SearchRequestBuilder setIgnoreIndices(IgnoreIndices ignoreIndices) {
request().ignoreIndices(ignoreIndices);
return this;
}
/**
* Constructs a new search source builder with a search query.
*

View File

@ -21,6 +21,7 @@ package org.elasticsearch.action.search;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.search.type.*;
import org.elasticsearch.action.support.IgnoreIndices;
import org.elasticsearch.action.support.TransportAction;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.ClusterState;
@ -87,7 +88,7 @@ public class TransportSearchAction extends TransportAction<SearchRequest, Search
if (optimizeSingleShard && searchRequest.searchType() != SCAN && searchRequest.searchType() != COUNT) {
try {
ClusterState clusterState = clusterService.state();
String[] concreteIndices = clusterState.metaData().concreteIndices(searchRequest.indices(), false, true);
String[] concreteIndices = clusterState.metaData().concreteIndices(searchRequest.indices(), searchRequest.ignoreIndices(), true);
Map<String, Set<String>> 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) {

View File

@ -108,7 +108,7 @@ public abstract class TransportSearchTypeAction extends TransportAction<SearchRe
clusterState.blocks().globalBlockedRaiseException(ClusterBlockLevel.READ);
String[] concreteIndices = clusterState.metaData().concreteIndices(request.indices(), false, true);
String[] concreteIndices = clusterState.metaData().concreteIndices(request.indices(), request.ignoreIndices(), true);
for (String index : concreteIndices) {
clusterState.blocks().indexBlockedRaiseException(ClusterBlockLevel.READ, index);

View File

@ -0,0 +1,65 @@
/*
* 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.action.support;
import org.elasticsearch.ElasticSearchIllegalArgumentException;
/**
* Specifies what type of requested indices to exclude.
*/
public enum IgnoreIndices {
DEFAULT((byte) 0),
NONE((byte) 1),
MISSING((byte) 2);
private final byte id;
private IgnoreIndices(byte id) {
this.id = id;
}
public byte id() {
return id;
}
public static IgnoreIndices fromId(byte id) {
if (id == 0) {
return DEFAULT;
} else if (id == 1) {
return NONE;
} else if(id == 2) {
return MISSING;
} else {
throw new ElasticSearchIllegalArgumentException("No valid missing index type id: " + id);
}
}
public static IgnoreIndices fromString(String type) {
if ("none".equals(type)) {
return NONE;
} else if ("missing".equals(type)) {
return MISSING;
} else {
throw new ElasticSearchIllegalArgumentException("No valid missing index type: " + type);
}
}
}

View File

@ -21,6 +21,7 @@ package org.elasticsearch.action.support.broadcast;
import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.support.IgnoreIndices;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
@ -37,6 +38,7 @@ public abstract class BroadcastOperationRequest implements ActionRequest {
private boolean listenerThreaded = false;
private BroadcastOperationThreading operationThreading = BroadcastOperationThreading.SINGLE_THREAD;
private IgnoreIndices ignoreIndices = IgnoreIndices.NONE;
protected BroadcastOperationRequest() {
@ -99,6 +101,15 @@ public abstract class BroadcastOperationRequest implements ActionRequest {
return operationThreading(BroadcastOperationThreading.fromString(operationThreading, this.operationThreading));
}
public IgnoreIndices ignoreIndices() {
return ignoreIndices;
}
public BroadcastOperationRequest ignoreIndices(IgnoreIndices ignoreIndices) {
this.ignoreIndices = ignoreIndices;
return this;
}
protected void beforeStart() {
}
@ -118,6 +129,7 @@ public abstract class BroadcastOperationRequest implements ActionRequest {
}
}
out.writeByte(operationThreading.id());
out.writeByte(ignoreIndices.id());
}
@Override
@ -132,5 +144,6 @@ public abstract class BroadcastOperationRequest implements ActionRequest {
}
}
operationThreading = BroadcastOperationThreading.fromId(in.readByte());
ignoreIndices = IgnoreIndices.fromId(in.readByte());
}
}

View File

@ -138,7 +138,7 @@ public abstract class TransportBroadcastOperationAction<Request extends Broadcas
throw blockException;
}
// update to concrete indices
String[] concreteIndices = clusterState.metaData().concreteIndices(request.indices(), false, true);
String[] concreteIndices = clusterState.metaData().concreteIndices(request.indices(), request.ignoreIndices(), true);
blockException = checkRequestBlock(clusterState, request, concreteIndices);
if (blockException != null) {
throw blockException;

View File

@ -25,6 +25,7 @@ import com.google.common.collect.Lists;
import com.google.common.collect.UnmodifiableIterator;
import gnu.trove.set.hash.THashSet;
import org.elasticsearch.ElasticSearchIllegalArgumentException;
import org.elasticsearch.action.support.IgnoreIndices;
import org.elasticsearch.cluster.block.ClusterBlock;
import org.elasticsearch.cluster.block.ClusterBlockLevel;
import org.elasticsearch.common.Nullable;
@ -342,7 +343,7 @@ public class MetaData implements Iterable<IndexMetaData> {
}
public Map<String, Set<String>> 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<String, Set<String>> resolveSearchRouting(@Nullable String routing, String[] aliasesOrIndices) {
@ -350,7 +351,7 @@ public class MetaData implements Iterable<IndexMetaData> {
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<IndexMetaData> {
* 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<IndexMetaData> {
}
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<IndexMetaData> {
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<IndexMetaData> {
return lst[0];
}
public String[] convertFromWildcards(String[] aliasesOrIndices, boolean wildcardOnlyOpen, boolean ignoreMissing) {
public String[] convertFromWildcards(String[] aliasesOrIndices, boolean wildcardOnlyOpen, IgnoreIndices ignoreIndices) {
Set<String> result = null;
for (int i = 0; i < aliasesOrIndices.length; i++) {
String aliasOrIndex = aliasesOrIndices[i];
@ -598,7 +598,7 @@ public class MetaData implements Iterable<IndexMetaData> {
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<IndexMetaData> {
}
}
}
if (!found && !ignoreMissing) {
if (!found && ignoreIndices != IgnoreIndices.MISSING) {
throw new IndexMissingException(new Index(aliasOrIndex));
}
}

View File

@ -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) {

View File

@ -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) {

View File

@ -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()));

View File

@ -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

View File

@ -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<GatewaySnapshotResponse>() {
@Override
public void onResponse(GatewaySnapshotResponse response) {

View File

@ -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()));

View File

@ -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

View File

@ -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

View File

@ -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();

View File

@ -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);

View File

@ -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) {

View File

@ -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);

View File

@ -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);

View File

@ -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;
}

View File

@ -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) {
}
}
}

View File

@ -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) {