Prevent throttled indices to be searched through wildcards by default (#34354)

Today if a wildcard, date-math expression or alias expands/resolves
to an index that is search-throttled we still search it. This is likely
not the desired behavior since it can unexpectedly slow down searches
significantly.

This change adds a new indices option that allows `search`, `count`
and `msearch` to ignore throttled indices by default. Users can
force expansion to throttled indices by using `ignore_throttled=true`
on the rest request to expand also to throttled indices.

Relates to #34352
This commit is contained in:
Simon Willnauer 2018-11-06 09:45:30 +01:00 committed by GitHub
parent 46c238d792
commit 833e0f8ecf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 268 additions and 92 deletions

View File

@ -108,7 +108,7 @@ public class RankEvalIT extends ESRestHighLevelClientTestCase {
// now try this when test2 is closed
client().performRequest(new Request("POST", "index2/_close"));
rankEvalRequest.indicesOptions(IndicesOptions.fromParameters(null, "true", null, SearchRequest.DEFAULT_INDICES_OPTIONS));
rankEvalRequest.indicesOptions(IndicesOptions.fromParameters(null, "true", null, "false", SearchRequest.DEFAULT_INDICES_OPTIONS));
response = execute(rankEvalRequest, highLevelClient()::rankEval, highLevelClient()::rankEvalAsync);
}

View File

@ -1055,7 +1055,8 @@ public class RequestConvertersTests extends ESTestCase {
IndicesOptions msearchDefault = new MultiSearchRequest().indicesOptions();
searchRequest.indicesOptions(IndicesOptions.fromOptions(randomlyGenerated.ignoreUnavailable(),
randomlyGenerated.allowNoIndices(), randomlyGenerated.expandWildcardsOpen(), randomlyGenerated.expandWildcardsClosed(),
msearchDefault.allowAliasesToMultipleIndices(), msearchDefault.forbidClosedIndices(), msearchDefault.ignoreAliases()));
msearchDefault.allowAliasesToMultipleIndices(), msearchDefault.forbidClosedIndices(), msearchDefault.ignoreAliases(),
msearchDefault.ignoreThrottled()));
multiSearchRequest.add(searchRequest);
}

View File

@ -38,7 +38,7 @@ public class ExplainLifecycleRequestTests extends ESTestCase {
}
if (randomBoolean()) {
IndicesOptions indicesOptions = IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(),
randomBoolean(), randomBoolean(), randomBoolean());
randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean());
request.indicesOptions(indicesOptions);
}
return request;
@ -54,7 +54,7 @@ public class ExplainLifecycleRequestTests extends ESTestCase {
break;
case 1:
indicesOptions = randomValueOtherThan(indicesOptions, () -> IndicesOptions.fromOptions(randomBoolean(), randomBoolean(),
randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean()));
randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean()));
break;
default:
throw new AssertionError("Illegal randomisation branch");

View File

@ -46,7 +46,7 @@ public class RemoveIndexLifecyclePolicyRequestTests extends ESTestCase {
if (randomBoolean()) {
return new RemoveIndexLifecyclePolicyRequest(Arrays.asList(generateRandomStringArray(20, 20, false)),
IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(),
randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean()));
randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean()));
} else {
return new RemoveIndexLifecyclePolicyRequest(Arrays.asList(generateRandomStringArray(20, 20, false)));
}
@ -57,14 +57,14 @@ public class RemoveIndexLifecyclePolicyRequestTests extends ESTestCase {
req.indicesOptions().ignoreUnavailable(), req.indicesOptions().allowNoIndices(),
req.indicesOptions().expandWildcardsOpen(), req.indicesOptions().expandWildcardsClosed(),
req.indicesOptions().allowAliasesToMultipleIndices(), req.indicesOptions().forbidClosedIndices(),
req.indicesOptions().ignoreAliases()));
req.indicesOptions().ignoreAliases(), req.indicesOptions().ignoreThrottled()));
}
private RemoveIndexLifecyclePolicyRequest mutateInstance(RemoveIndexLifecyclePolicyRequest req) {
if (randomBoolean()) {
return new RemoveIndexLifecyclePolicyRequest(req.indices(),
randomValueOtherThan(req.indicesOptions(), () -> IndicesOptions.fromOptions(randomBoolean(), randomBoolean(),
randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean())));
randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean())));
} else {
return new RemoveIndexLifecyclePolicyRequest(
randomValueOtherThan(req.indices(), () -> Arrays.asList(generateRandomStringArray(20, 20, false))),

View File

@ -45,7 +45,7 @@ public class MultiSearchTemplateRequest extends ActionRequest implements Composi
private int maxConcurrentSearchRequests = 0;
private List<SearchTemplateRequest> requests = new ArrayList<>();
private IndicesOptions indicesOptions = IndicesOptions.strictExpandOpenAndForbidClosed();
private IndicesOptions indicesOptions = IndicesOptions.strictExpandOpenAndForbidClosedIgnoreThrottled();
/**
* Add a search template request to execute. Note, the order is important, the search response will be returned in the

View File

@ -286,7 +286,7 @@ public class RankEvalRequestIT extends ESIntegTestCase {
// test that ignore_unavailable=true works but returns one result less
assertTrue(client().admin().indices().prepareClose("test2").get().isAcknowledged());
request.indicesOptions(IndicesOptions.fromParameters(null, "true", null, SearchRequest.DEFAULT_INDICES_OPTIONS));
request.indicesOptions(IndicesOptions.fromParameters(null, "true", null, "false", SearchRequest.DEFAULT_INDICES_OPTIONS));
response = client().execute(RankEvalAction.INSTANCE, request).actionGet();
details = (PrecisionAtK.Detail) response.getPartialResults().get("amsterdam_query").getMetricDetails();
assertEquals(6, details.getRetrieved());
@ -294,37 +294,37 @@ public class RankEvalRequestIT extends ESIntegTestCase {
// test that ignore_unavailable=false or default settings throw an IndexClosedException
assertTrue(client().admin().indices().prepareClose("test2").get().isAcknowledged());
request.indicesOptions(IndicesOptions.fromParameters(null, "false", null, SearchRequest.DEFAULT_INDICES_OPTIONS));
request.indicesOptions(IndicesOptions.fromParameters(null, "false", null, "false", SearchRequest.DEFAULT_INDICES_OPTIONS));
response = client().execute(RankEvalAction.INSTANCE, request).actionGet();
assertEquals(1, response.getFailures().size());
assertThat(response.getFailures().get("amsterdam_query"), instanceOf(IndexClosedException.class));
// test expand_wildcards
request = new RankEvalRequest(task, new String[] { "tes*" });
request.indicesOptions(IndicesOptions.fromParameters("none", null, null, SearchRequest.DEFAULT_INDICES_OPTIONS));
request.indicesOptions(IndicesOptions.fromParameters("none", null, null, "false", SearchRequest.DEFAULT_INDICES_OPTIONS));
response = client().execute(RankEvalAction.INSTANCE, request).actionGet();
details = (PrecisionAtK.Detail) response.getPartialResults().get("amsterdam_query").getMetricDetails();
assertEquals(0, details.getRetrieved());
request.indicesOptions(IndicesOptions.fromParameters("open", null, null, SearchRequest.DEFAULT_INDICES_OPTIONS));
request.indicesOptions(IndicesOptions.fromParameters("open", null, null, "false", SearchRequest.DEFAULT_INDICES_OPTIONS));
response = client().execute(RankEvalAction.INSTANCE, request).actionGet();
details = (PrecisionAtK.Detail) response.getPartialResults().get("amsterdam_query").getMetricDetails();
assertEquals(6, details.getRetrieved());
assertEquals(5, details.getRelevantRetrieved());
request.indicesOptions(IndicesOptions.fromParameters("closed", null, null, SearchRequest.DEFAULT_INDICES_OPTIONS));
request.indicesOptions(IndicesOptions.fromParameters("closed", null, null, "false", SearchRequest.DEFAULT_INDICES_OPTIONS));
response = client().execute(RankEvalAction.INSTANCE, request).actionGet();
assertEquals(1, response.getFailures().size());
assertThat(response.getFailures().get("amsterdam_query"), instanceOf(IndexClosedException.class));
// test allow_no_indices
request = new RankEvalRequest(task, new String[] { "bad*" });
request.indicesOptions(IndicesOptions.fromParameters(null, null, "true", SearchRequest.DEFAULT_INDICES_OPTIONS));
request.indicesOptions(IndicesOptions.fromParameters(null, null, "true", "false", SearchRequest.DEFAULT_INDICES_OPTIONS));
response = client().execute(RankEvalAction.INSTANCE, request).actionGet();
details = (PrecisionAtK.Detail) response.getPartialResults().get("amsterdam_query").getMetricDetails();
assertEquals(0, details.getRetrieved());
request.indicesOptions(IndicesOptions.fromParameters(null, null, "false", SearchRequest.DEFAULT_INDICES_OPTIONS));
request.indicesOptions(IndicesOptions.fromParameters(null, null, "false", "false", SearchRequest.DEFAULT_INDICES_OPTIONS));
response = client().execute(RankEvalAction.INSTANCE, request).actionGet();
assertEquals(1, response.getFailures().size());
assertThat(response.getFailures().get("amsterdam_query"), instanceOf(IndexNotFoundException.class));

View File

@ -59,7 +59,8 @@ public class RankEvalRequestTests extends AbstractWireSerializingTestCase<RankEv
}
RankEvalRequest rankEvalRequest = new RankEvalRequest(RankEvalSpecTests.createTestItem(), indices);
IndicesOptions indicesOptions = IndicesOptions.fromOptions(
randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean());
randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(),
randomBoolean());
rankEvalRequest.indicesOptions(indicesOptions);
return rankEvalRequest;
}

View File

@ -20,6 +20,10 @@
"type" : "boolean",
"description" : "Whether specified concrete indices should be ignored when unavailable (missing or closed)"
},
"ignore_throttled": {
"type" : "boolean",
"description" : "Whether specified concrete, expanded or aliased indices should be ignored when throttled"
},
"allow_no_indices": {
"type" : "boolean",
"description" : "Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified)"

View File

@ -58,6 +58,10 @@
"type" : "boolean",
"description" : "Whether specified concrete indices should be ignored when unavailable (missing or closed)"
},
"ignore_throttled": {
"type" : "boolean",
"description" : "Whether specified concrete, expanded or aliased indices should be ignored when throttled"
},
"allow_no_indices": {
"type" : "boolean",
"description" : "Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified)"

View File

@ -20,6 +20,10 @@
"type" : "boolean",
"description" : "Whether specified concrete indices should be ignored when unavailable (missing or closed)"
},
"ignore_throttled": {
"type" : "boolean",
"description" : "Whether specified concrete, expanded or aliased indices should be ignored when throttled"
},
"allow_no_indices": {
"type" : "boolean",
"description" : "Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified)"

View File

@ -67,7 +67,7 @@ public class IndicesAliasesRequest extends AcknowledgedRequest<IndicesAliasesReq
// indices options that require every specified index to exist, expand wildcards only to open
// indices, don't allow that no indices are resolved from wildcard expressions and resolve the
// expressions only against indices
private static final IndicesOptions INDICES_OPTIONS = IndicesOptions.fromOptions(false, false, true, false, true, false, true);
private static final IndicesOptions INDICES_OPTIONS = IndicesOptions.fromOptions(false, false, true, false, true, false, true, false);
public IndicesAliasesRequest() {
}

View File

@ -38,7 +38,7 @@ public class DeleteIndexRequest extends AcknowledgedRequest<DeleteIndexRequest>
private String[] indices;
// Delete index should work by default on both open and closed indices.
private IndicesOptions indicesOptions = IndicesOptions.fromOptions(false, true, true, true, false, false, true);
private IndicesOptions indicesOptions = IndicesOptions.fromOptions(false, true, true, true, false, false, true, false);
public DeleteIndexRequest() {
}

View File

@ -58,7 +58,7 @@ public class MultiSearchRequest extends ActionRequest implements CompositeIndice
private int maxConcurrentSearchRequests = 0;
private List<SearchRequest> requests = new ArrayList<>();
private IndicesOptions indicesOptions = IndicesOptions.strictExpandOpenAndForbidClosed();
private IndicesOptions indicesOptions = IndicesOptions.strictExpandOpenAndForbidClosedIgnoreThrottled();
/**
* Add a search request to execute. Note, the order is important, the search response will be returned in the
@ -287,7 +287,7 @@ public class MultiSearchRequest extends ActionRequest implements CompositeIndice
}
return output.toByteArray();
}
public static void writeSearchRequestParams(SearchRequest request, XContentBuilder xContentBuilder) throws IOException {
xContentBuilder.startObject();
if (request.indices() != null) {

View File

@ -28,6 +28,7 @@ import org.elasticsearch.client.ElasticsearchClient;
*/
public class MultiSearchRequestBuilder extends ActionRequestBuilder<MultiSearchRequest, MultiSearchResponse> {
public MultiSearchRequestBuilder(ElasticsearchClient client, MultiSearchAction action) {
super(client, action, new MultiSearchRequest());
}
@ -40,7 +41,8 @@ public class MultiSearchRequestBuilder extends ActionRequestBuilder<MultiSearchR
* will not be used (if set).
*/
public MultiSearchRequestBuilder add(SearchRequest request) {
if (request.indicesOptions() == IndicesOptions.strictExpandOpenAndForbidClosed() && request().indicesOptions() != IndicesOptions.strictExpandOpenAndForbidClosed()) {
if (request.indicesOptions() == IndicesOptions.strictExpandOpenAndForbidClosed()
&& request().indicesOptions() != IndicesOptions.strictExpandOpenAndForbidClosed()) {
request.indicesOptions(request().indicesOptions());
}
@ -53,7 +55,8 @@ public class MultiSearchRequestBuilder extends ActionRequestBuilder<MultiSearchR
* same order as the search requests.
*/
public MultiSearchRequestBuilder add(SearchRequestBuilder request) {
if (request.request().indicesOptions() == IndicesOptions.strictExpandOpenAndForbidClosed() && request().indicesOptions() != IndicesOptions.strictExpandOpenAndForbidClosed()) {
if (request.request().indicesOptions() == SearchRequest.DEFAULT_INDICES_OPTIONS
&& request().indicesOptions() != SearchRequest.DEFAULT_INDICES_OPTIONS) {
request.request().indicesOptions(request().indicesOptions());
}

View File

@ -88,7 +88,7 @@ public final class SearchRequest extends ActionRequest implements IndicesRequest
private String[] types = Strings.EMPTY_ARRAY;
public static final IndicesOptions DEFAULT_INDICES_OPTIONS = IndicesOptions.strictExpandOpenAndForbidClosed();
public static final IndicesOptions DEFAULT_INDICES_OPTIONS = IndicesOptions.strictExpandOpenAndForbidClosedIgnoreThrottled();
private IndicesOptions indicesOptions = DEFAULT_INDICES_OPTIONS;

View File

@ -81,7 +81,8 @@ public class IndicesOptions implements ToXContentFragment {
IGNORE_ALIASES,
ALLOW_NO_INDICES,
FORBID_ALIASES_TO_MULTIPLE_INDICES,
FORBID_CLOSED_INDICES;
FORBID_CLOSED_INDICES,
IGNORE_THROTTLED;
public static final EnumSet<Option> NONE = EnumSet.noneOf(Option.class);
}
@ -94,6 +95,9 @@ public class IndicesOptions implements ToXContentFragment {
new IndicesOptions(EnumSet.of(Option.ALLOW_NO_INDICES), EnumSet.of(WildcardStates.OPEN, WildcardStates.CLOSED));
public static final IndicesOptions STRICT_EXPAND_OPEN_FORBID_CLOSED =
new IndicesOptions(EnumSet.of(Option.ALLOW_NO_INDICES, Option.FORBID_CLOSED_INDICES), EnumSet.of(WildcardStates.OPEN));
public static final IndicesOptions STRICT_EXPAND_OPEN_FORBID_CLOSED_IGNORE_THROTTLED =
new IndicesOptions(EnumSet.of(Option.ALLOW_NO_INDICES, Option.FORBID_CLOSED_INDICES, Option.IGNORE_THROTTLED),
EnumSet.of(WildcardStates.OPEN));
public static final IndicesOptions STRICT_SINGLE_INDEX_NO_EXPAND_FORBID_CLOSED =
new IndicesOptions(EnumSet.of(Option.FORBID_ALIASES_TO_MULTIPLE_INDICES, Option.FORBID_CLOSED_INDICES),
EnumSet.noneOf(WildcardStates.class));
@ -242,7 +246,21 @@ public class IndicesOptions implements ToXContentFragment {
return options.contains(Option.IGNORE_ALIASES);
}
/**
*
* @return whether indices that are marked as throttled should be ignored when resolving a wildcard or alias
*/
public boolean ignoreThrottled() {
return options.contains(Option.IGNORE_THROTTLED);
}
public void writeIndicesOptions(StreamOutput out) throws IOException {
EnumSet<Option> options = this.options;
// never write this out to a pre7.0 version
if (out.getVersion().before(Version.V_7_0_0_alpha1) && options.contains(Option.IGNORE_THROTTLED)) {
options = EnumSet.copyOf(options);
options.remove(Option.IGNORE_THROTTLED);
}
if (out.getVersion().onOrAfter(Version.V_6_4_0)) {
out.writeEnumSet(options);
out.writeEnumSet(expandWildcards);
@ -265,17 +283,19 @@ public class IndicesOptions implements ToXContentFragment {
public static IndicesOptions fromOptions(boolean ignoreUnavailable, boolean allowNoIndices, boolean expandToOpenIndices,
boolean expandToClosedIndices) {
return fromOptions(ignoreUnavailable, allowNoIndices, expandToOpenIndices, expandToClosedIndices, true, false, false);
return fromOptions(ignoreUnavailable, allowNoIndices, expandToOpenIndices, expandToClosedIndices, true, false, false, false);
}
public static IndicesOptions fromOptions(boolean ignoreUnavailable, boolean allowNoIndices, boolean expandToOpenIndices,
boolean expandToClosedIndices, IndicesOptions defaultOptions) {
return fromOptions(ignoreUnavailable, allowNoIndices, expandToOpenIndices, expandToClosedIndices,
defaultOptions.allowAliasesToMultipleIndices(), defaultOptions.forbidClosedIndices(), defaultOptions.ignoreAliases());
defaultOptions.allowAliasesToMultipleIndices(), defaultOptions.forbidClosedIndices(), defaultOptions.ignoreAliases(),
defaultOptions.ignoreThrottled());
}
public static IndicesOptions fromOptions(boolean ignoreUnavailable, boolean allowNoIndices, boolean expandToOpenIndices,
boolean expandToClosedIndices, boolean allowAliasesToMultipleIndices, boolean forbidClosedIndices, boolean ignoreAliases) {
boolean expandToClosedIndices, boolean allowAliasesToMultipleIndices, boolean forbidClosedIndices, boolean ignoreAliases,
boolean ignoreThrottled) {
final Set<Option> opts = new HashSet<>();
final Set<WildcardStates> wildcards = new HashSet<>();
@ -300,6 +320,9 @@ public class IndicesOptions implements ToXContentFragment {
if (ignoreAliases) {
opts.add(Option.IGNORE_ALIASES);
}
if (ignoreThrottled) {
opts.add(Option.IGNORE_THROTTLED);
}
return new IndicesOptions(opts, wildcards);
}
@ -309,6 +332,7 @@ public class IndicesOptions implements ToXContentFragment {
request.param("expand_wildcards"),
request.param("ignore_unavailable"),
request.param("allow_no_indices"),
request.param("ignore_throttled"),
defaultSettings);
}
@ -317,6 +341,7 @@ public class IndicesOptions implements ToXContentFragment {
map.containsKey("expand_wildcards") ? map.get("expand_wildcards") : map.get("expandWildcards"),
map.containsKey("ignore_unavailable") ? map.get("ignore_unavailable") : map.get("ignoreUnavailable"),
map.containsKey("allow_no_indices") ? map.get("allow_no_indices") : map.get("allowNoIndices"),
map.containsKey("ignore_throttled") ? map.get("ignore_throttled") : map.get("ignoreThrottled"),
defaultSettings);
}
@ -327,12 +352,13 @@ public class IndicesOptions implements ToXContentFragment {
public static boolean isIndicesOptions(String name) {
return "expand_wildcards".equals(name) || "expandWildcards".equals(name) ||
"ignore_unavailable".equals(name) || "ignoreUnavailable".equals(name) ||
"ignore_throttled".equals(name) || "ignoreThrottled".equals(name) ||
"allow_no_indices".equals(name) || "allowNoIndices".equals(name);
}
public static IndicesOptions fromParameters(Object wildcardsString, Object ignoreUnavailableString, Object allowNoIndicesString,
IndicesOptions defaultSettings) {
if (wildcardsString == null && ignoreUnavailableString == null && allowNoIndicesString == null) {
Object ignoreThrottled, IndicesOptions defaultSettings) {
if (wildcardsString == null && ignoreUnavailableString == null && allowNoIndicesString == null && ignoreThrottled == null) {
return defaultSettings;
}
@ -346,7 +372,8 @@ public class IndicesOptions implements ToXContentFragment {
wildcards.contains(WildcardStates.CLOSED),
defaultSettings.allowAliasesToMultipleIndices(),
defaultSettings.forbidClosedIndices(),
defaultSettings.ignoreAliases()
defaultSettings.ignoreAliases(),
nodeBooleanValue(ignoreThrottled, "ignore_throttled", defaultSettings.ignoreThrottled())
);
}
@ -359,6 +386,7 @@ public class IndicesOptions implements ToXContentFragment {
builder.endArray();
builder.field("ignore_unavailable", ignoreUnavailable());
builder.field("allow_no_indices", allowNoIndices());
builder.field("ignore_throttled", ignoreThrottled());
return builder;
}
@ -379,6 +407,15 @@ public class IndicesOptions implements ToXContentFragment {
return STRICT_EXPAND_OPEN_FORBID_CLOSED;
}
/**
* @return indices options that requires every specified index to exist, expands wildcards only to open indices,
* allows that no indices are resolved from wildcard expressions (not returning an error) and forbids the
* use of closed indices by throwing an error and ignores indices that are throttled.
*/
public static IndicesOptions strictExpandOpenAndForbidClosedIgnoreThrottled() {
return STRICT_EXPAND_OPEN_FORBID_CLOSED_IGNORE_THROTTLED;
}
/**
* @return indices option that requires every specified index to exist, expands wildcards to both open and closed
* indices and allows that no indices are resolved from wildcard expressions (not returning an error).
@ -433,6 +470,7 @@ public class IndicesOptions implements ToXContentFragment {
", allow_aliases_to_multiple_indices=" + allowAliasesToMultipleIndices() +
", forbid_closed_indices=" + forbidClosedIndices() +
", ignore_aliases=" + ignoreAliases() +
", ignore_throttled=" + ignoreThrottled() +
']';
}
}

View File

@ -34,6 +34,7 @@ import org.elasticsearch.common.time.JavaDateMathParser;
import org.elasticsearch.common.util.set.Sets;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.indices.IndexClosedException;
import org.elasticsearch.indices.InvalidIndexNameException;
@ -146,6 +147,7 @@ public class IndexNameExpressionResolver {
if (indexExpressions == null || indexExpressions.length == 0) {
indexExpressions = new String[]{MetaData.ALL};
}
Set<String> originalIndexExpression = Sets.newHashSet(indexExpressions);
MetaData metaData = context.getState().metaData();
IndicesOptions options = context.getOptions();
final boolean failClosed = options.forbidClosedIndices() && options.ignoreUnavailable() == false;
@ -195,7 +197,9 @@ public class IndexNameExpressionResolver {
" The write index may be explicitly disabled using is_write_index=false or the alias points to multiple" +
" indices without one being designated as a write index");
}
concreteIndices.add(writeIndex.getIndex());
if (addIndex(writeIndex, context, originalIndexExpression)) {
concreteIndices.add(writeIndex.getIndex());
}
} else {
if (aliasOrIndex.getIndices().size() > 1 && !options.allowAliasesToMultipleIndices()) {
String[] indexNames = new String[aliasOrIndex.getIndices().size()];
@ -212,12 +216,14 @@ public class IndexNameExpressionResolver {
if (failClosed) {
throw new IndexClosedException(index.getIndex());
} else {
if (options.forbidClosedIndices() == false) {
if (options.forbidClosedIndices() == false && addIndex(index, context, originalIndexExpression)) {
concreteIndices.add(index.getIndex());
}
}
} else if (index.getState() == IndexMetaData.State.OPEN) {
concreteIndices.add(index.getIndex());
if (addIndex(index, context, originalIndexExpression)) {
concreteIndices.add(index.getIndex());
}
} else {
throw new IllegalStateException("index state [" + index.getState() + "] not supported");
}
@ -233,6 +239,15 @@ public class IndexNameExpressionResolver {
return concreteIndices.toArray(new Index[concreteIndices.size()]);
}
private static boolean addIndex(IndexMetaData metaData, Context context, Set<String> originalIndices) {
if (context.options.ignoreThrottled()) {
if (originalIndices.contains(metaData.getIndex().getName()) == false) {
return IndexSettings.INDEX_SEARCH_THROTTLED.get(metaData.getSettings()) == false;
}
}
return true;
}
private static IllegalArgumentException aliasesNotSupportedException(String expression) {
return new IllegalArgumentException("The provided expression [" + expression + "] matches an " +
"alias, specify the corresponding concrete indices instead.");

View File

@ -21,7 +21,6 @@ package org.elasticsearch.action.search;
import org.elasticsearch.Version;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.OriginalIndices;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.cluster.routing.GroupShardsIterator;
import org.elasticsearch.cluster.routing.ShardRouting;
@ -71,7 +70,7 @@ public class CanMatchPreFilterSearchPhaseTests extends ESTestCase {
AtomicReference<GroupShardsIterator<SearchShardIterator>> result = new AtomicReference<>();
CountDownLatch latch = new CountDownLatch(1);
GroupShardsIterator<SearchShardIterator> shardsIter = SearchAsyncActionTests.getShardsIter("idx",
new OriginalIndices(new String[]{"idx"}, IndicesOptions.strictExpandOpenAndForbidClosed()),
new OriginalIndices(new String[]{"idx"}, SearchRequest.DEFAULT_INDICES_OPTIONS),
2, randomBoolean(), primaryNode, replicaNode);
final SearchRequest searchRequest = new SearchRequest();
searchRequest.allowPartialSearchResults(true);
@ -138,7 +137,7 @@ public class CanMatchPreFilterSearchPhaseTests extends ESTestCase {
AtomicReference<GroupShardsIterator<SearchShardIterator>> result = new AtomicReference<>();
CountDownLatch latch = new CountDownLatch(1);
GroupShardsIterator<SearchShardIterator> shardsIter = SearchAsyncActionTests.getShardsIter("idx",
new OriginalIndices(new String[]{"idx"}, IndicesOptions.strictExpandOpenAndForbidClosed()),
new OriginalIndices(new String[]{"idx"}, SearchRequest.DEFAULT_INDICES_OPTIONS),
2, randomBoolean(), primaryNode, replicaNode);
final SearchRequest searchRequest = new SearchRequest();
@ -194,7 +193,7 @@ public class CanMatchPreFilterSearchPhaseTests extends ESTestCase {
};
final CountDownLatch latch = new CountDownLatch(1);
final OriginalIndices originalIndices = new OriginalIndices(new String[]{"idx"}, IndicesOptions.strictExpandOpenAndForbidClosed());
final OriginalIndices originalIndices = new OriginalIndices(new String[]{"idx"}, SearchRequest.DEFAULT_INDICES_OPTIONS);
final GroupShardsIterator<SearchShardIterator> shardsIter =
SearchAsyncActionTests.getShardsIter("idx", originalIndices, 4096, randomBoolean(), primaryNode, replicaNode);
final ExecutorService executor = Executors.newFixedThreadPool(randomIntBetween(1, Runtime.getRuntime().availableProcessors()));

View File

@ -58,27 +58,27 @@ public class MultiSearchRequestTests extends ESTestCase {
assertThat(request.requests().get(0).indices()[0],
equalTo("test"));
assertThat(request.requests().get(0).indicesOptions(),
equalTo(IndicesOptions.fromOptions(true, true, true, true, IndicesOptions.strictExpandOpenAndForbidClosed())));
equalTo(IndicesOptions.fromOptions(true, true, true, true, SearchRequest.DEFAULT_INDICES_OPTIONS)));
assertThat(request.requests().get(0).types().length,
equalTo(0));
assertThat(request.requests().get(1).indices()[0],
equalTo("test"));
assertThat(request.requests().get(1).indicesOptions(),
equalTo(IndicesOptions.fromOptions(false, true, true, true, IndicesOptions.strictExpandOpenAndForbidClosed())));
equalTo(IndicesOptions.fromOptions(false, true, true, true, SearchRequest.DEFAULT_INDICES_OPTIONS)));
assertThat(request.requests().get(1).types()[0],
equalTo("type1"));
assertThat(request.requests().get(2).indices()[0],
equalTo("test"));
assertThat(request.requests().get(2).indicesOptions(),
equalTo(IndicesOptions.fromOptions(false, true, true, false, IndicesOptions.strictExpandOpenAndForbidClosed())));
equalTo(IndicesOptions.fromOptions(false, true, true, false, SearchRequest.DEFAULT_INDICES_OPTIONS)));
assertThat(request.requests().get(3).indices()[0],
equalTo("test"));
assertThat(request.requests().get(3).indicesOptions(),
equalTo(IndicesOptions.fromOptions(true, true, true, true, IndicesOptions.strictExpandOpenAndForbidClosed())));
equalTo(IndicesOptions.fromOptions(true, true, true, true, SearchRequest.DEFAULT_INDICES_OPTIONS)));
assertThat(request.requests().get(4).indices()[0],
equalTo("test"));
assertThat(request.requests().get(4).indicesOptions(),
equalTo(IndicesOptions.fromOptions(true, false, false, true, IndicesOptions.strictExpandOpenAndForbidClosed())));
equalTo(IndicesOptions.fromOptions(true, false, false, true, SearchRequest.DEFAULT_INDICES_OPTIONS)));
assertThat(request.requests().get(5).indices(), is(Strings.EMPTY_ARRAY));
assertThat(request.requests().get(5).types().length, equalTo(0));
@ -98,7 +98,7 @@ public class MultiSearchRequestTests extends ESTestCase {
assertThat(request.requests().size(), equalTo(1));
assertThat(request.requests().get(0).indices()[0], equalTo("test"));
assertThat(request.requests().get(0).indicesOptions(),
equalTo(IndicesOptions.fromOptions(true, true, true, true, IndicesOptions.strictExpandOpenAndForbidClosed())));
equalTo(IndicesOptions.fromOptions(true, true, true, true, SearchRequest.DEFAULT_INDICES_OPTIONS)));
assertThat(request.requests().get(0).types().length, equalTo(0));
}
@ -276,11 +276,11 @@ public class MultiSearchRequestTests extends ESTestCase {
// only expand_wildcards, ignore_unavailable and allow_no_indices can be specified from msearch api, so unset other options:
IndicesOptions randomlyGenerated = searchRequest.indicesOptions();
IndicesOptions msearchDefault = IndicesOptions.strictExpandOpenAndForbidClosed();
IndicesOptions msearchDefault = SearchRequest.DEFAULT_INDICES_OPTIONS;
searchRequest.indicesOptions(IndicesOptions.fromOptions(
randomlyGenerated.ignoreUnavailable(), randomlyGenerated.allowNoIndices(), randomlyGenerated.expandWildcardsOpen(),
randomlyGenerated.expandWildcardsClosed(), msearchDefault.allowAliasesToMultipleIndices(),
msearchDefault.forbidClosedIndices(), msearchDefault.ignoreAliases()
msearchDefault.forbidClosedIndices(), msearchDefault.ignoreAliases(), msearchDefault.ignoreThrottled()
));
request.add(searchRequest);

View File

@ -21,7 +21,6 @@ package org.elasticsearch.action.search;
import org.elasticsearch.Version;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.OriginalIndices;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.cluster.routing.GroupShardsIterator;
import org.elasticsearch.cluster.routing.RecoverySource;
@ -82,7 +81,7 @@ public class SearchAsyncActionTests extends ESTestCase {
AtomicInteger contextIdGenerator = new AtomicInteger(0);
GroupShardsIterator<SearchShardIterator> shardsIter = getShardsIter("idx",
new OriginalIndices(new String[]{"idx"}, IndicesOptions.strictExpandOpenAndForbidClosed()),
new OriginalIndices(new String[]{"idx"}, SearchRequest.DEFAULT_INDICES_OPTIONS),
10, randomBoolean(), primaryNode, replicaNode);
int numSkipped = 0;
for (SearchShardIterator iter : shardsIter) {
@ -182,7 +181,7 @@ public class SearchAsyncActionTests extends ESTestCase {
AtomicInteger contextIdGenerator = new AtomicInteger(0);
GroupShardsIterator<SearchShardIterator> shardsIter = getShardsIter("idx",
new OriginalIndices(new String[]{"idx"}, IndicesOptions.strictExpandOpenAndForbidClosed()),
new OriginalIndices(new String[]{"idx"}, SearchRequest.DEFAULT_INDICES_OPTIONS),
10, randomBoolean(), primaryNode, replicaNode);
SearchTransportService transportService = new SearchTransportService(null, null);
Map<String, Transport.Connection> lookup = new HashMap<>();
@ -282,7 +281,7 @@ public class SearchAsyncActionTests extends ESTestCase {
Map<DiscoveryNode, Set<Long>> nodeToContextMap = newConcurrentMap();
AtomicInteger contextIdGenerator = new AtomicInteger(0);
GroupShardsIterator<SearchShardIterator> shardsIter = getShardsIter("idx",
new OriginalIndices(new String[]{"idx"}, IndicesOptions.strictExpandOpenAndForbidClosed()),
new OriginalIndices(new String[]{"idx"}, SearchRequest.DEFAULT_INDICES_OPTIONS),
randomIntBetween(1, 10), randomBoolean(), primaryNode, replicaNode);
AtomicInteger numFreedContext = new AtomicInteger();
SearchTransportService transportService = new SearchTransportService(null, null) {

View File

@ -80,7 +80,7 @@ public class TransportSearchActionTests extends ESTestCase {
GroupShardsIterator<ShardIterator> localShardsIterator = new GroupShardsIterator<>(localShardIterators);
OriginalIndices localIndices = new OriginalIndices(new String[]{"local_alias", "local_index_2"},
IndicesOptions.strictExpandOpenAndForbidClosed());
SearchRequest.DEFAULT_INDICES_OPTIONS);
OriginalIndices remoteIndices = new OriginalIndices(new String[]{"remote_alias", "remote_index_2"},
IndicesOptions.strictExpandOpen());
@ -185,9 +185,9 @@ public class TransportSearchActionTests extends ESTestCase {
Map<String, OriginalIndices> remoteIndicesByCluster = new HashMap<>();
remoteIndicesByCluster.put("test_cluster_1",
new OriginalIndices(new String[]{"fo*", "ba*"}, IndicesOptions.strictExpandOpenAndForbidClosed()));
new OriginalIndices(new String[]{"fo*", "ba*"}, SearchRequest.DEFAULT_INDICES_OPTIONS));
remoteIndicesByCluster.put("test_cluster_2",
new OriginalIndices(new String[]{"x*"}, IndicesOptions.strictExpandOpenAndForbidClosed()));
new OriginalIndices(new String[]{"x*"}, SearchRequest.DEFAULT_INDICES_OPTIONS));
Map<String, AliasFilter> remoteAliases = new HashMap<>();
TransportSearchAction.processRemoteShards(searchShardsResponseMap, remoteIndicesByCluster, iteratorList,
remoteAliases);
@ -274,6 +274,6 @@ public class TransportSearchActionTests extends ESTestCase {
localIndices[i] = randomAlphaOfLengthBetween(3, 10);
}
return new OriginalIndices(localIndices, IndicesOptions.fromOptions(randomBoolean(),
randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean()));
randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean()));
}
}

View File

@ -53,7 +53,8 @@ public class IndicesOptionsTests extends ESTestCase {
for (int i = 0; i < iterations; i++) {
Version version = randomVersionBetween(random(), Version.V_7_0_0_alpha1, null);
IndicesOptions indicesOptions = IndicesOptions.fromOptions(
randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean());
randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(),
randomBoolean());
BytesStreamOutput output = new BytesStreamOutput();
output.setVersion(version);
@ -80,7 +81,7 @@ public class IndicesOptionsTests extends ESTestCase {
for (int i = 0; i < iterations; i++) {
Version version = randomVersionBetween(random(), null, Version.V_6_4_0);
IndicesOptions indicesOptions = IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(),
randomBoolean(), randomBoolean(), randomBoolean());
randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean());
BytesStreamOutput output = new BytesStreamOutput();
output.setVersion(version);
@ -99,6 +100,7 @@ public class IndicesOptionsTests extends ESTestCase {
assertThat(indicesOptions2.allowAliasesToMultipleIndices(), equalTo(indicesOptions.allowAliasesToMultipleIndices()));
assertEquals(indicesOptions2.ignoreAliases(), indicesOptions.ignoreAliases());
assertFalse(indicesOptions2.ignoreThrottled()); // make sure we never write this option to pre 7.0
}
}
@ -110,9 +112,10 @@ public class IndicesOptionsTests extends ESTestCase {
boolean allowAliasesToMultipleIndices = randomBoolean();
boolean forbidClosedIndices = randomBoolean();
boolean ignoreAliases = randomBoolean();
boolean ingoreThrottled = randomBoolean();
IndicesOptions indicesOptions = IndicesOptions.fromOptions(ignoreUnavailable, allowNoIndices,expandToOpenIndices,
expandToClosedIndices, allowAliasesToMultipleIndices, forbidClosedIndices, ignoreAliases);
expandToClosedIndices, allowAliasesToMultipleIndices, forbidClosedIndices, ignoreAliases, ingoreThrottled);
assertThat(indicesOptions.ignoreUnavailable(), equalTo(ignoreUnavailable));
assertThat(indicesOptions.allowNoIndices(), equalTo(allowNoIndices));
@ -122,6 +125,7 @@ public class IndicesOptionsTests extends ESTestCase {
assertThat(indicesOptions.allowAliasesToMultipleIndices(), equalTo(allowAliasesToMultipleIndices));
assertThat(indicesOptions.forbidClosedIndices(), equalTo(forbidClosedIndices));
assertEquals(ignoreAliases, indicesOptions.ignoreAliases());
assertEquals(ingoreThrottled, indicesOptions.ignoreThrottled());
}
public void testFromOptionsWithDefaultOptions() {
@ -131,7 +135,7 @@ public class IndicesOptionsTests extends ESTestCase {
boolean expandToClosedIndices = randomBoolean();
IndicesOptions defaultOptions = IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(),
randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean());
randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean());
IndicesOptions indicesOptions = IndicesOptions.fromOptions(ignoreUnavailable, allowNoIndices,expandToOpenIndices,
expandToClosedIndices, defaultOptions);
@ -164,14 +168,16 @@ public class IndicesOptionsTests extends ESTestCase {
}
boolean ignoreUnavailable = randomBoolean();
String ignoreUnavailableString = Boolean.toString(ignoreUnavailable);
boolean ignoreThrottled = randomBoolean();
String ignoreThrottledString = Boolean.toString(ignoreThrottled);
boolean allowNoIndices = randomBoolean();
String allowNoIndicesString = Boolean.toString(allowNoIndices);
IndicesOptions defaultOptions = IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(),
randomBoolean(), randomBoolean(), randomBoolean());
randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean());
IndicesOptions updatedOptions = IndicesOptions.fromParameters(expandWildcardsString, ignoreUnavailableString,
allowNoIndicesString, defaultOptions);
allowNoIndicesString, ignoreThrottled, defaultOptions);
assertEquals(expandWildcardsOpen, updatedOptions.expandWildcardsOpen());
assertEquals(expandWildcardsClosed, updatedOptions.expandWildcardsClosed());
@ -185,19 +191,19 @@ public class IndicesOptionsTests extends ESTestCase {
public void testSimpleByteBWC() {
Map<Byte, IndicesOptions> old = new HashMap<>();
// These correspond to each individual option (bit) in the old byte-based IndicesOptions
old.put((byte) 0, IndicesOptions.fromOptions(false, false, false, false, true, false, false));
old.put((byte) 1, IndicesOptions.fromOptions(true, false, false, false, true, false, false));
old.put((byte) 2, IndicesOptions.fromOptions(false, true, false, false, true, false, false));
old.put((byte) 4, IndicesOptions.fromOptions(false, false, true, false, true, false, false));
old.put((byte) 8, IndicesOptions.fromOptions(false, false, false, true, true, false, false));
old.put((byte) 16, IndicesOptions.fromOptions(false, false, false, false, false, false, false));
old.put((byte) 32, IndicesOptions.fromOptions(false, false, false, false, true, true, false));
old.put((byte) 64, IndicesOptions.fromOptions(false, false, false, false, true, false, true));
old.put((byte) 0, IndicesOptions.fromOptions(false, false, false, false, true, false, false, false));
old.put((byte) 1, IndicesOptions.fromOptions(true, false, false, false, true, false, false, false));
old.put((byte) 2, IndicesOptions.fromOptions(false, true, false, false, true, false, false, false));
old.put((byte) 4, IndicesOptions.fromOptions(false, false, true, false, true, false, false, false));
old.put((byte) 8, IndicesOptions.fromOptions(false, false, false, true, true, false, false, false));
old.put((byte) 16, IndicesOptions.fromOptions(false, false, false, false, false, false, false, false));
old.put((byte) 32, IndicesOptions.fromOptions(false, false, false, false, true, true, false, false));
old.put((byte) 64, IndicesOptions.fromOptions(false, false, false, false, true, false, true, false));
// Test a few multi-selected options
old.put((byte) 13, IndicesOptions.fromOptions(true, false, true, true, true, false, false));
old.put((byte) 19, IndicesOptions.fromOptions(true, true, false, false, false, false, false));
old.put((byte) 24, IndicesOptions.fromOptions(false, false, false, true, false, false, false));
old.put((byte) 123, IndicesOptions.fromOptions(true, true, false, true, false, true, true));
old.put((byte) 13, IndicesOptions.fromOptions(true, false, true, true, true, false, false, false));
old.put((byte) 19, IndicesOptions.fromOptions(true, true, false, false, false, false, false, false));
old.put((byte) 24, IndicesOptions.fromOptions(false, false, false, true, false, false, false, false));
old.put((byte) 123, IndicesOptions.fromOptions(true, true, false, true, false, true, true, false));
for (Map.Entry<Byte, IndicesOptions> entry : old.entrySet()) {
IndicesOptions indicesOptions2 = IndicesOptions.fromByte(entry.getKey());
@ -209,11 +215,13 @@ public class IndicesOptionsTests extends ESTestCase {
public void testEqualityAndHashCode() {
IndicesOptions indicesOptions = IndicesOptions.fromOptions(
randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean());
randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(),
randomBoolean());
EqualsHashCodeTestUtils.checkEqualsAndHashCode(indicesOptions, opts -> {
return IndicesOptions.fromOptions(opts.ignoreUnavailable(), opts.allowNoIndices(), opts.expandWildcardsOpen(),
opts.expandWildcardsClosed(), opts.allowAliasesToMultipleIndices(), opts.forbidClosedIndices(), opts.ignoreAliases());
opts.expandWildcardsClosed(), opts.allowAliasesToMultipleIndices(), opts.forbidClosedIndices(), opts.ignoreAliases(),
opts.ignoreThrottled());
}, opts -> {
boolean mutated = false;
boolean ignoreUnavailable = opts.ignoreUnavailable();
@ -223,6 +231,7 @@ public class IndicesOptionsTests extends ESTestCase {
boolean allowAliasesToMulti = opts.allowAliasesToMultipleIndices();
boolean forbidClosed = opts.forbidClosedIndices();
boolean ignoreAliases = opts.ignoreAliases();
boolean ignoreThrottled = opts.ignoreThrottled();
while (mutated == false) {
if (randomBoolean()) {
ignoreUnavailable = !ignoreUnavailable;
@ -252,9 +261,13 @@ public class IndicesOptionsTests extends ESTestCase {
ignoreAliases = !ignoreAliases;
mutated = true;
}
if (randomBoolean()) {
ignoreThrottled = !ignoreThrottled;
mutated = true;
}
}
return IndicesOptions.fromOptions(ignoreUnavailable, allowNoIndices, expandOpen, expandClosed,
allowAliasesToMulti, forbidClosed, ignoreAliases);
allowAliasesToMulti, forbidClosed, ignoreAliases, ignoreThrottled);
});
}
@ -264,6 +277,7 @@ public class IndicesOptionsTests extends ESTestCase {
null : randomSubsetOf(Arrays.asList("open", "closed"));
Boolean ignoreUnavailable = randomBoolean() ? null : randomBoolean();
Boolean allowNoIndices = randomBoolean() ? null : randomBoolean();
Boolean ignoreThrottled = randomBoolean() ? null : randomBoolean();
Map<String, Object> settings = new HashMap<>();
@ -279,6 +293,10 @@ public class IndicesOptionsTests extends ESTestCase {
settings.put("allow_no_indices", allowNoIndices);
}
if (ignoreThrottled != null) {
settings.put("ignore_throttled", ignoreThrottled);
}
IndicesOptions fromMap = IndicesOptions.fromMap(settings, defaults);
boolean open = wildcardStates != null ? wildcardStates.contains("open") : defaults.expandWildcardsOpen();
@ -288,6 +306,7 @@ public class IndicesOptionsTests extends ESTestCase {
assertEquals(fromMap.ignoreUnavailable(), ignoreUnavailable == null ? defaults.ignoreUnavailable() : ignoreUnavailable);
assertEquals(fromMap.allowNoIndices(), allowNoIndices == null ? defaults.allowNoIndices() : allowNoIndices);
assertEquals(fromMap.ignoreThrottled(), ignoreThrottled == null ? defaults.ignoreThrottled() : ignoreThrottled);
}
public void testToXContent() throws IOException {
@ -320,5 +339,6 @@ public class IndicesOptionsTests extends ESTestCase {
}
assertEquals(map.get("ignore_unavailable"), options.contains(Option.IGNORE_UNAVAILABLE));
assertEquals(map.get("allow_no_indices"), options.contains(Option.ALLOW_NO_INDICES));
assertEquals(map.get("ignore_throttled"), options.contains(Option.IGNORE_THROTTLED));
}
}

View File

@ -32,14 +32,18 @@ import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.IndexMetaData.State;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.indices.IndexClosedException;
import org.elasticsearch.indices.InvalidIndexNameException;
import org.elasticsearch.test.ESTestCase;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.List;
import java.util.function.Function;
@ -525,8 +529,12 @@ public class IndexNameExpressionResolverTests extends ESTestCase {
}
private static IndexMetaData.Builder indexBuilder(String index) {
return IndexMetaData.builder(index).settings(settings(Version.CURRENT).put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0));
return IndexMetaData.builder(index).settings(settings());
}
private static Settings.Builder settings() {
return settings(Version.CURRENT).put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0);
}
public void testConcreteIndicesIgnoreIndicesOneMissingIndex() {
@ -664,7 +672,7 @@ public class IndexNameExpressionResolverTests extends ESTestCase {
// when ignoreAliases option is set, concreteIndexNames resolves the provided expressions
// only against the defined indices
IndicesOptions ignoreAliasesOptions = IndicesOptions.fromOptions(false, false, true, false, true, false, true);
IndicesOptions ignoreAliasesOptions = IndicesOptions.fromOptions(false, false, true, false, true, false, true, false);
String[] indexNamesIndexWildcard = indexNameExpressionResolver.concreteIndexNames(state, ignoreAliasesOptions, "foo*");
@ -688,7 +696,7 @@ public class IndexNameExpressionResolverTests extends ESTestCase {
// when ignoreAliases option is not set, concreteIndexNames resolves the provided
// expressions against the defined indices and aliases
IndicesOptions indicesAndAliasesOptions = IndicesOptions.fromOptions(false, false, true, false, true, false, false);
IndicesOptions indicesAndAliasesOptions = IndicesOptions.fromOptions(false, false, true, false, true, false, false, false);
List<String> indexNames = Arrays.asList(indexNameExpressionResolver.concreteIndexNames(state, indicesAndAliasesOptions, "foo*"));
assertEquals(2, indexNames.size());
@ -1191,13 +1199,13 @@ public class IndexNameExpressionResolverTests extends ESTestCase {
}
{
DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest("test-alias");
deleteIndexRequest.indicesOptions(IndicesOptions.fromOptions(true, true, true, true, false, false, true));
deleteIndexRequest.indicesOptions(IndicesOptions.fromOptions(true, true, true, true, false, false, true, false));
String[] indices = indexNameExpressionResolver.concreteIndexNames(state, deleteIndexRequest);
assertEquals(0, indices.length);
}
{
DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest("test-a*");
deleteIndexRequest.indicesOptions(IndicesOptions.fromOptions(randomBoolean(), false, true, true, false, false, true));
deleteIndexRequest.indicesOptions(IndicesOptions.fromOptions(randomBoolean(), false, true, true, false, false, true, false));
IndexNotFoundException infe = expectThrows(IndexNotFoundException.class,
() -> indexNameExpressionResolver.concreteIndexNames(state, deleteIndexRequest));
assertEquals(infe.getIndex().getName(), "test-a*");
@ -1311,4 +1319,69 @@ public class IndexNameExpressionResolverTests extends ESTestCase {
() -> indexNameExpressionResolver.concreteIndexNames(context, "_foo"));
assertEquals("Invalid index name [_foo], must not start with '_'.", iine.getMessage());
}
public void testIgnoreThrottled() {
MetaData.Builder mdBuilder = MetaData.builder()
.put(indexBuilder("test-index").state(State.OPEN)
.settings(settings().put(IndexSettings.INDEX_SEARCH_THROTTLED.getKey(), true))
.putAlias(AliasMetaData.builder("test-alias")))
.put(indexBuilder("index").state(State.OPEN)
.putAlias(AliasMetaData.builder("test-alias2")))
.put(indexBuilder("index-closed").state(State.CLOSE)
.settings(settings().put(IndexSettings.INDEX_SEARCH_THROTTLED.getKey(), true))
.putAlias(AliasMetaData.builder("test-alias-closed")));
ClusterState state = ClusterState.builder(new ClusterName("_name")).metaData(mdBuilder).build();
{
Index[] indices = indexNameExpressionResolver.concreteIndices(state,
IndicesOptions.STRICT_EXPAND_OPEN_FORBID_CLOSED_IGNORE_THROTTLED, "*");
assertEquals(1, indices.length);
assertEquals("index", indices[0].getName());
}
{
Index[] indices = indexNameExpressionResolver.concreteIndices(state,
IndicesOptions.STRICT_EXPAND_OPEN_FORBID_CLOSED, "test-alias");
assertEquals(1, indices.length);
assertEquals("test-index", indices[0].getName());
}
{
Index[] indices = indexNameExpressionResolver.concreteIndices(state,
IndicesOptions.STRICT_EXPAND_OPEN_FORBID_CLOSED_IGNORE_THROTTLED, "test-alias");
assertEquals(0, indices.length);
}
{
Index[] indices = indexNameExpressionResolver.concreteIndices(state,
IndicesOptions.STRICT_EXPAND_OPEN_FORBID_CLOSED_IGNORE_THROTTLED, "test-*");
assertEquals(1, indices.length);
assertEquals("index", indices[0].getName());
}
{
Index[] indices = indexNameExpressionResolver.concreteIndices(state,
IndicesOptions.STRICT_EXPAND_OPEN_FORBID_CLOSED_IGNORE_THROTTLED, "ind*", "test-index");
assertEquals(2, indices.length);
Arrays.sort(indices, Comparator.comparing(Index::getName));
assertEquals("index", indices[0].getName());
assertEquals("test-index", indices[1].getName());
}
{
Index[] indices = indexNameExpressionResolver.concreteIndices(state,
new IndicesOptions(EnumSet.of(IndicesOptions.Option.ALLOW_NO_INDICES,
IndicesOptions.Option.IGNORE_THROTTLED),
EnumSet.of(IndicesOptions.WildcardStates.OPEN)), "ind*", "test-index");
assertEquals(2, indices.length);
Arrays.sort(indices, Comparator.comparing(Index::getName));
assertEquals("index", indices[0].getName());
assertEquals("test-index", indices[1].getName());
}
{
Index[] indices = indexNameExpressionResolver.concreteIndices(state,
new IndicesOptions(EnumSet.of(IndicesOptions.Option.ALLOW_NO_INDICES),
EnumSet.of(IndicesOptions.WildcardStates.OPEN, IndicesOptions.WildcardStates.CLOSED)), "ind*", "test-index");
assertEquals(3, indices.length);
Arrays.sort(indices, Comparator.comparing(Index::getName));
assertEquals("index", indices[0].getName());
assertEquals("index-closed", indices[1].getName());
assertEquals("test-index", indices[2].getName());
}
}
}

View File

@ -153,16 +153,16 @@ public class WildcardExpressionResolverTests extends ESTestCase {
IndexNameExpressionResolver.WildcardExpressionResolver resolver = new IndexNameExpressionResolver.WildcardExpressionResolver();
// when ignoreAliases option is not set, WildcardExpressionResolver resolves the provided
// expressions against the defined indices and aliases
IndicesOptions indicesAndAliasesOptions = IndicesOptions.fromOptions(randomBoolean(), randomBoolean(),
true, false, true, false, false);
IndicesOptions indicesAndAliasesOptions = IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), true, false, true, false,
false, false);
IndexNameExpressionResolver.Context indicesAndAliasesContext =
new IndexNameExpressionResolver.Context(state, indicesAndAliasesOptions);
// ignoreAliases option is set, WildcardExpressionResolver throws error when
IndicesOptions skipAliasesIndicesOptions = IndicesOptions.fromOptions(true, true, true, false, true, false, true);
IndicesOptions skipAliasesIndicesOptions = IndicesOptions.fromOptions(true, true, true, false, true, false, true, false);
IndexNameExpressionResolver.Context skipAliasesLenientContext =
new IndexNameExpressionResolver.Context(state, skipAliasesIndicesOptions);
// ignoreAliases option is set, WildcardExpressionResolver resolves the provided expressions only against the defined indices
IndicesOptions errorOnAliasIndicesOptions = IndicesOptions.fromOptions(false, false, true, false, true, false, true);
IndicesOptions errorOnAliasIndicesOptions = IndicesOptions.fromOptions(false, false, true, false, true, false, true, false);
IndexNameExpressionResolver.Context skipAliasesStrictContext =
new IndexNameExpressionResolver.Context(state, errorOnAliasIndicesOptions);
@ -217,13 +217,13 @@ public class WildcardExpressionResolverTests extends ESTestCase {
// when ignoreAliases option is not set, WildcardExpressionResolver resolves the provided
// expressions against the defined indices and aliases
IndicesOptions indicesAndAliasesOptions = IndicesOptions.fromOptions(false, false, true, false, true, false, false);
IndicesOptions indicesAndAliasesOptions = IndicesOptions.fromOptions(false, false, true, false, true, false, false, false);
IndexNameExpressionResolver.Context indicesAndAliasesContext =
new IndexNameExpressionResolver.Context(state, indicesAndAliasesOptions);
// ignoreAliases option is set, WildcardExpressionResolver resolves the provided expressions
// only against the defined indices
IndicesOptions onlyIndicesOptions = IndicesOptions.fromOptions(false, false, true, false, true, false, true);
IndicesOptions onlyIndicesOptions = IndicesOptions.fromOptions(false, false, true, false, true, false, true, false);
IndexNameExpressionResolver.Context onlyIndicesContext = new IndexNameExpressionResolver.Context(state, onlyIndicesOptions);
{

View File

@ -28,6 +28,7 @@ import org.elasticsearch.action.search.SearchPhaseExecutionException;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchTask;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.action.support.PlainActionFuture;
import org.elasticsearch.action.support.WriteRequest;
import org.elasticsearch.common.Strings;
@ -85,6 +86,7 @@ import static java.util.Collections.singletonList;
import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE;
import static org.elasticsearch.indices.cluster.IndicesClusterStateService.AllocatedIndices.IndexRemovalReason.DELETED;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchHits;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.instanceOf;
@ -552,4 +554,17 @@ public class SearchServiceTests extends ESSingleNodeTestCase {
// we still make sure can match is executed on the network thread
service.canMatch(req, ActionListener.wrap(r -> assertSame(Thread.currentThread(), currentThread), e -> fail("unexpected")));
}
public void testExpandSearchThrottled() {
createIndex("throttled_threadpool_index");
client().execute(
InternalOrPrivateSettingsPlugin.UpdateInternalOrPrivateAction.INSTANCE,
new InternalOrPrivateSettingsPlugin.UpdateInternalOrPrivateAction.Request("throttled_threadpool_index",
IndexSettings.INDEX_SEARCH_THROTTLED.getKey(), "true"))
.actionGet();
client().prepareIndex("throttled_threadpool_index", "_doc", "1").setSource("field", "value").setRefreshPolicy(IMMEDIATE).get();
assertHitCount(client().prepareSearch().get(), 0L);
assertHitCount(client().prepareSearch().setIndicesOptions(IndicesOptions.STRICT_EXPAND_OPEN_FORBID_CLOSED).get(), 1L);
}
}

View File

@ -23,7 +23,7 @@ public class ExplainLifecycleRequestTests extends AbstractWireSerializingTestCas
}
if (randomBoolean()) {
IndicesOptions indicesOptions = IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(),
randomBoolean(), randomBoolean(), randomBoolean());
randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean());
request.indicesOptions(indicesOptions);
}
return request;
@ -40,7 +40,7 @@ public class ExplainLifecycleRequestTests extends AbstractWireSerializingTestCas
break;
case 1:
indicesOptions = randomValueOtherThan(indicesOptions, () -> IndicesOptions.fromOptions(randomBoolean(), randomBoolean(),
randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean()));
randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean()));
break;
default:
throw new AssertionError("Illegal randomisation branch");

View File

@ -20,7 +20,7 @@ public class RemoveIndexLifecyclePolicyRequestTests extends AbstractStreamableTe
Request request = new Request(generateRandomStringArray(20, 20, false));
if (randomBoolean()) {
IndicesOptions indicesOptions = IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(),
randomBoolean(), randomBoolean(), randomBoolean());
randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean());
request.indicesOptions(indicesOptions);
}
if (randomBoolean()) {
@ -45,7 +45,7 @@ public class RemoveIndexLifecyclePolicyRequestTests extends AbstractStreamableTe
break;
case 1:
indicesOptions = randomValueOtherThan(indicesOptions, () -> IndicesOptions.fromOptions(randomBoolean(), randomBoolean(),
randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean()));
randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean()));
break;
default:
throw new AssertionError("Illegal randomisation branch");

View File

@ -23,7 +23,7 @@ public class RetryRequestTests extends AbstractStreamableTestCase<Request> {
}
if (randomBoolean()) {
IndicesOptions indicesOptions = IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(),
randomBoolean(), randomBoolean(), randomBoolean());
randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean());
request.indicesOptions(indicesOptions);
}
return request;
@ -40,7 +40,7 @@ public class RetryRequestTests extends AbstractStreamableTestCase<Request> {
break;
case 1:
indicesOptions = randomValueOtherThan(indicesOptions, () -> IndicesOptions.fromOptions(randomBoolean(), randomBoolean(),
randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean()));
randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean()));
break;
default:
throw new AssertionError("Illegal randomisation branch");