Remove (deprecated) support for '+' in index expressions (#25274)

Relates to #24515
This commit is contained in:
Luca Cavanna 2017-06-19 15:19:17 +02:00 committed by GitHub
parent e4f4886d40
commit d9ec2a23c5
5 changed files with 9 additions and 52 deletions

View File

@ -29,8 +29,6 @@ import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.joda.DateMathParser; import org.elasticsearch.common.joda.DateMathParser;
import org.elasticsearch.common.joda.FormatDateTimeFormatter; import org.elasticsearch.common.joda.FormatDateTimeFormatter;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.regex.Regex; import org.elasticsearch.common.regex.Regex;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.Index; import org.elasticsearch.index.Index;
@ -58,8 +56,6 @@ public class IndexNameExpressionResolver extends AbstractComponent {
private final List<ExpressionResolver> expressionResolvers; private final List<ExpressionResolver> expressionResolvers;
private final DateMathExpressionResolver dateMathExpressionResolver; private final DateMathExpressionResolver dateMathExpressionResolver;
private static final DeprecationLogger DEPRECATION_LOGGER =
new DeprecationLogger(Loggers.getLogger(IndexNameExpressionResolver.class));
public IndexNameExpressionResolver(Settings settings) { public IndexNameExpressionResolver(Settings settings) {
super(settings); super(settings);
@ -592,7 +588,6 @@ public class IndexNameExpressionResolver extends AbstractComponent {
private Set<String> innerResolve(Context context, List<String> expressions, IndicesOptions options, MetaData metaData) { private Set<String> innerResolve(Context context, List<String> expressions, IndicesOptions options, MetaData metaData) {
Set<String> result = null; Set<String> result = null;
boolean wildcardSeen = false; boolean wildcardSeen = false;
boolean plusSeen = false;
for (int i = 0; i < expressions.size(); i++) { for (int i = 0; i < expressions.size(); i++) {
String expression = expressions.get(i); String expression = expressions.get(i);
if (aliasOrIndexExists(metaData, expression)) { if (aliasOrIndexExists(metaData, expression)) {
@ -605,14 +600,7 @@ public class IndexNameExpressionResolver extends AbstractComponent {
throw infe(expression); throw infe(expression);
} }
boolean add = true; boolean add = true;
if (expression.charAt(0) == '+') { if (expression.charAt(0) == '-') {
// if its the first, add empty result set
plusSeen = true;
if (i == 0) {
result = new HashSet<>();
}
expression = expression.substring(1);
} else if (expression.charAt(0) == '-') {
// if there is a negation without a wildcard being previously seen, add it verbatim, // if there is a negation without a wildcard being previously seen, add it verbatim,
// otherwise return the expression // otherwise return the expression
if (wildcardSeen) { if (wildcardSeen) {
@ -655,9 +643,6 @@ public class IndexNameExpressionResolver extends AbstractComponent {
wildcardSeen = true; wildcardSeen = true;
} }
} }
if (plusSeen) {
DEPRECATION_LOGGER.deprecated("support for '+' as part of index expressions is deprecated");
}
return result; return result;
} }

View File

@ -1027,24 +1027,6 @@ public class IndexNameExpressionResolverTests extends ESTestCase {
assertArrayEquals(new String[] {"test-alias-0", "test-alias-1", "test-alias-non-filtering"}, strings); assertArrayEquals(new String[] {"test-alias-0", "test-alias-1", "test-alias-non-filtering"}, strings);
} }
public void testConcreteIndicesForDeprecatedPattern() {
MetaData.Builder mdBuilder = MetaData.builder()
.put(indexBuilder("testXXX").state(State.OPEN))
.put(indexBuilder("testXXY").state(State.OPEN))
.put(indexBuilder("testYYY").state(State.OPEN));
ClusterState state = ClusterState.builder(new ClusterName("_name")).metaData(mdBuilder).build();
IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state,
IndicesOptions.fromOptions(true, true, true, true));
assertThat(newHashSet(indexNameExpressionResolver.concreteIndexNames(context, "+testX*")),
equalTo(newHashSet("testXXX", "testXXY")));
assertThat(newHashSet(indexNameExpressionResolver.concreteIndexNames(context, "+testXXX", "+testXXY", "+testYYY", "-testYYY")),
equalTo(newHashSet("testXXX", "testXXY", "testYYY")));
assertThat(newHashSet(indexNameExpressionResolver.concreteIndexNames(context, "+testXX*", "+testY*")),
equalTo(newHashSet("testXXX", "testXXY", "testYYY")));
assertWarnings("support for '+' as part of index expressions is deprecated");
}
public void testDeleteIndexIgnoresAliases() { public void testDeleteIndexIgnoresAliases() {
MetaData.Builder mdBuilder = MetaData.builder() MetaData.Builder mdBuilder = MetaData.builder()
.put(indexBuilder("test-index").state(State.OPEN) .put(indexBuilder("test-index").state(State.OPEN)

View File

@ -182,20 +182,4 @@ public class WildcardExpressionResolverTests extends ESTestCase {
private IndexMetaData.Builder indexBuilder(String index) { private 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(Version.CURRENT).put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1).put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0));
} }
public void testForDeprecatedPlusPattern() {
MetaData.Builder mdBuilder = MetaData.builder()
.put(indexBuilder("testXXX").state(IndexMetaData.State.OPEN))
.put(indexBuilder("testXYY").state(IndexMetaData.State.OPEN))
.put(indexBuilder("testYYY").state(IndexMetaData.State.OPEN));
ClusterState state = ClusterState.builder(new ClusterName("_name")).metaData(mdBuilder).build();
IndexNameExpressionResolver.WildcardExpressionResolver resolver = new IndexNameExpressionResolver.WildcardExpressionResolver();
IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, true, true, true));
assertThat(newHashSet(resolver.resolve(context, Arrays.asList("+testX*", "-testYYY"))), equalTo(newHashSet("testXXX", "testXYY")));
assertThat(newHashSet(resolver.resolve(context, Arrays.asList("+testYYY", "+testXY*"))), equalTo(newHashSet("testYYY", "testXYY")));
assertThat(newHashSet(resolver.resolve(context, Arrays.asList("testYYY", "+testXX*"))), equalTo(newHashSet("testXXX", "testYYY")));
assertWarnings("support for '+' as part of index expressions is deprecated");
}
} }

View File

@ -20,8 +20,8 @@ API, unless otherwise specified.
Most APIs that refer to an `index` parameter support execution across multiple indices, Most APIs that refer to an `index` parameter support execution across multiple indices,
using simple `test1,test2,test3` notation (or `_all` for all indices). It also using simple `test1,test2,test3` notation (or `_all` for all indices). It also
support wildcards, for example: `test*` or `*test` or `te*t` or `*test*`, and the ability to "add" (`+`) support wildcards, for example: `test*` or `*test` or `te*t` or `*test*`, and the
and "remove" (`-`), for example: `+test*,-test3`. ability to "exclude" (`-`), for example: `test*,-test3`.
All multi indices API support the following url query string parameters: All multi indices API support the following url query string parameters:

View File

@ -62,3 +62,9 @@ which will expand to matching indices).
The index parameter in the delete index API no longer accepts alias names. The index parameter in the delete index API no longer accepts alias names.
Instead, it accepts only index names (or wildcards which will expand to Instead, it accepts only index names (or wildcards which will expand to
matching indices). matching indices).
==== Support for '+' has been removed in index expressions
Omitting the '+' has the same effect as specifying it, hence support for '+'
has been removed in index expressions.