Deprecate use of + in index names (#24585)
Use of '+' in index names is implicit. There is no need to support it. This commit deprecates support for it. Closes #24515
This commit is contained in:
parent
bd364c56a8
commit
fdb6cd8088
|
@ -29,6 +29,8 @@ 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;
|
||||||
|
@ -55,6 +57,8 @@ 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);
|
||||||
|
@ -159,7 +163,6 @@ public class IndexNameExpressionResolver extends AbstractComponent {
|
||||||
if (indexExpressions.length == 1) {
|
if (indexExpressions.length == 1) {
|
||||||
failNoIndices = options.allowNoIndices() == false;
|
failNoIndices = options.allowNoIndices() == false;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> expressions = Arrays.asList(indexExpressions);
|
List<String> expressions = Arrays.asList(indexExpressions);
|
||||||
for (ExpressionResolver expressionResolver : expressionResolvers) {
|
for (ExpressionResolver expressionResolver : expressionResolvers) {
|
||||||
expressions = expressionResolver.resolve(context, expressions);
|
expressions = expressionResolver.resolve(context, expressions);
|
||||||
|
@ -588,6 +591,7 @@ 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)) {
|
||||||
|
@ -602,6 +606,7 @@ public class IndexNameExpressionResolver extends AbstractComponent {
|
||||||
boolean add = true;
|
boolean add = true;
|
||||||
if (expression.charAt(0) == '+') {
|
if (expression.charAt(0) == '+') {
|
||||||
// if its the first, add empty result set
|
// if its the first, add empty result set
|
||||||
|
plusSeen = true;
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
result = new HashSet<>();
|
result = new HashSet<>();
|
||||||
}
|
}
|
||||||
|
@ -649,6 +654,9 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,6 @@ import org.elasticsearch.test.ESTestCase;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.function.Predicate;
|
|
||||||
|
|
||||||
import static org.elasticsearch.common.util.set.Sets.newHashSet;
|
import static org.elasticsearch.common.util.set.Sets.newHashSet;
|
||||||
import static org.hamcrest.Matchers.arrayContaining;
|
import static org.hamcrest.Matchers.arrayContaining;
|
||||||
|
@ -621,7 +620,7 @@ public class IndexNameExpressionResolverTests extends ESTestCase {
|
||||||
assertThat(newHashSet(indexNameExpressionResolver.concreteIndexNames(context, "test*", "-testXXX")),
|
assertThat(newHashSet(indexNameExpressionResolver.concreteIndexNames(context, "test*", "-testXXX")),
|
||||||
equalTo(newHashSet("testYYX", "testXYY", "testYYY", "testXXY")));
|
equalTo(newHashSet("testYYX", "testXYY", "testYYY", "testXXY")));
|
||||||
|
|
||||||
assertThat(newHashSet(indexNameExpressionResolver.concreteIndexNames(context, "+testXXX", "+testXXY", "+testYYY", "-testYYY")),
|
assertThat(newHashSet(indexNameExpressionResolver.concreteIndexNames(context, "testXXX", "testXXY", "testYYY", "-testYYY")),
|
||||||
equalTo(newHashSet("testXXX", "testXXY", "testYYY", "-testYYY")));
|
equalTo(newHashSet("testXXX", "testXXY", "testYYY", "-testYYY")));
|
||||||
|
|
||||||
assertThat(newHashSet(indexNameExpressionResolver.concreteIndexNames(context, "testYYY", "testYYX", "testX*", "-testXXX")),
|
assertThat(newHashSet(indexNameExpressionResolver.concreteIndexNames(context, "testYYY", "testYYX", "testX*", "-testXXX")),
|
||||||
|
@ -637,7 +636,7 @@ public class IndexNameExpressionResolverTests extends ESTestCase {
|
||||||
equalTo(newHashSet("-testXYZ", "-testXZZ", "-testYYY")));
|
equalTo(newHashSet("-testXYZ", "-testXZZ", "-testYYY")));
|
||||||
|
|
||||||
assertThat(newHashSet(indexNameExpressionResolver.concreteIndexNames(state, IndicesOptions.lenientExpandOpen(),
|
assertThat(newHashSet(indexNameExpressionResolver.concreteIndexNames(state, IndicesOptions.lenientExpandOpen(),
|
||||||
"+testXXX", "+testXXY", "+testXYY", "-testXXY")),
|
"testXXX", "testXXY", "testXYY", "-testXXY")),
|
||||||
equalTo(newHashSet("testXXX", "testXYY", "testXXY")));
|
equalTo(newHashSet("testXXX", "testXYY", "testXXY")));
|
||||||
|
|
||||||
indexNames = indexNameExpressionResolver.concreteIndexNames(state, IndicesOptions.lenientExpandOpen(), "*", "-*");
|
indexNames = indexNameExpressionResolver.concreteIndexNames(state, IndicesOptions.lenientExpandOpen(), "*", "-*");
|
||||||
|
@ -817,7 +816,7 @@ public class IndexNameExpressionResolverTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testIsPatternMatchingAllIndicesMatchingSingleExclusion() throws Exception {
|
public void testIsPatternMatchingAllIndicesMatchingSingleExclusion() throws Exception {
|
||||||
String[] indicesOrAliases = new String[]{"-index1", "+index1"};
|
String[] indicesOrAliases = new String[]{"-index1", "index1"};
|
||||||
String[] concreteIndices = new String[]{"index1", "index2", "index3"};
|
String[] concreteIndices = new String[]{"index1", "index2", "index3"};
|
||||||
MetaData metaData = metaDataBuilder(concreteIndices);
|
MetaData metaData = metaDataBuilder(concreteIndices);
|
||||||
assertThat(indexNameExpressionResolver.isPatternMatchingAllIndices(metaData, indicesOrAliases, concreteIndices), equalTo(true));
|
assertThat(indexNameExpressionResolver.isPatternMatchingAllIndices(metaData, indicesOrAliases, concreteIndices), equalTo(true));
|
||||||
|
@ -832,7 +831,7 @@ public class IndexNameExpressionResolverTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testIsPatternMatchingAllIndicesMatchingTrailingWildcardAndExclusion() throws Exception {
|
public void testIsPatternMatchingAllIndicesMatchingTrailingWildcardAndExclusion() throws Exception {
|
||||||
String[] indicesOrAliases = new String[]{"index*", "-index1", "+index1"};
|
String[] indicesOrAliases = new String[]{"index*", "-index1", "index1"};
|
||||||
String[] concreteIndices = new String[]{"index1", "index2", "index3"};
|
String[] concreteIndices = new String[]{"index1", "index2", "index3"};
|
||||||
MetaData metaData = metaDataBuilder(concreteIndices);
|
MetaData metaData = metaDataBuilder(concreteIndices);
|
||||||
assertThat(indexNameExpressionResolver.isPatternMatchingAllIndices(metaData, indicesOrAliases, concreteIndices), equalTo(true));
|
assertThat(indexNameExpressionResolver.isPatternMatchingAllIndices(metaData, indicesOrAliases, concreteIndices), equalTo(true));
|
||||||
|
@ -970,4 +969,22 @@ public class IndexNameExpressionResolverTests extends ESTestCase {
|
||||||
Arrays.sort(strings);
|
Arrays.sort(strings);
|
||||||
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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,9 +49,9 @@ public class WildcardExpressionResolverTests extends ESTestCase {
|
||||||
assertThat(newHashSet(resolver.resolve(context, Arrays.asList("testX*", "kuku"))), equalTo(newHashSet("testXXX", "testXYY", "kuku")));
|
assertThat(newHashSet(resolver.resolve(context, Arrays.asList("testX*", "kuku"))), equalTo(newHashSet("testXXX", "testXYY", "kuku")));
|
||||||
assertThat(newHashSet(resolver.resolve(context, Arrays.asList("*"))), equalTo(newHashSet("testXXX", "testXYY", "testYYY", "kuku")));
|
assertThat(newHashSet(resolver.resolve(context, Arrays.asList("*"))), equalTo(newHashSet("testXXX", "testXYY", "testYYY", "kuku")));
|
||||||
assertThat(newHashSet(resolver.resolve(context, Arrays.asList("*", "-kuku"))), equalTo(newHashSet("testXXX", "testXYY", "testYYY")));
|
assertThat(newHashSet(resolver.resolve(context, Arrays.asList("*", "-kuku"))), equalTo(newHashSet("testXXX", "testXYY", "testYYY")));
|
||||||
assertThat(newHashSet(resolver.resolve(context, Arrays.asList("testXXX", "+testYYY"))), equalTo(newHashSet("testXXX", "testYYY")));
|
assertThat(newHashSet(resolver.resolve(context, Arrays.asList("testXXX", "testYYY"))), equalTo(newHashSet("testXXX", "testYYY")));
|
||||||
assertThat(newHashSet(resolver.resolve(context, Arrays.asList("testXXX", "-testXXX"))), equalTo(newHashSet("testXXX", "-testXXX")));
|
assertThat(newHashSet(resolver.resolve(context, Arrays.asList("testXXX", "-testXXX"))), equalTo(newHashSet("testXXX", "-testXXX")));
|
||||||
assertThat(newHashSet(resolver.resolve(context, Arrays.asList("testXXX", "+testY*"))), equalTo(newHashSet("testXXX", "testYYY")));
|
assertThat(newHashSet(resolver.resolve(context, Arrays.asList("testXXX", "testY*"))), equalTo(newHashSet("testXXX", "testYYY")));
|
||||||
assertThat(newHashSet(resolver.resolve(context, Arrays.asList("testXXX", "-testX*"))), equalTo(newHashSet("testXXX")));
|
assertThat(newHashSet(resolver.resolve(context, Arrays.asList("testXXX", "-testX*"))), equalTo(newHashSet("testXXX")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,9 +67,9 @@ public class WildcardExpressionResolverTests extends ESTestCase {
|
||||||
IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen());
|
IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen());
|
||||||
assertThat(newHashSet(resolver.resolve(context, Arrays.asList("testYY*", "alias*"))), equalTo(newHashSet("testXXX", "testXYY", "testYYY")));
|
assertThat(newHashSet(resolver.resolve(context, Arrays.asList("testYY*", "alias*"))), equalTo(newHashSet("testXXX", "testXYY", "testYYY")));
|
||||||
assertThat(newHashSet(resolver.resolve(context, Arrays.asList("-kuku"))), equalTo(newHashSet("-kuku")));
|
assertThat(newHashSet(resolver.resolve(context, Arrays.asList("-kuku"))), equalTo(newHashSet("-kuku")));
|
||||||
assertThat(newHashSet(resolver.resolve(context, Arrays.asList("+test*", "-testYYY"))), equalTo(newHashSet("testXXX", "testXYY")));
|
assertThat(newHashSet(resolver.resolve(context, Arrays.asList("test*", "-testYYY"))), equalTo(newHashSet("testXXX", "testXYY")));
|
||||||
assertThat(newHashSet(resolver.resolve(context, Arrays.asList("+testX*", "+testYYY"))), equalTo(newHashSet("testXXX", "testXYY", "testYYY")));
|
assertThat(newHashSet(resolver.resolve(context, Arrays.asList("testX*", "testYYY"))), equalTo(newHashSet("testXXX", "testXYY", "testYYY")));
|
||||||
assertThat(newHashSet(resolver.resolve(context, Arrays.asList("+testYYY", "+testX*"))), equalTo(newHashSet("testXXX", "testXYY", "testYYY")));
|
assertThat(newHashSet(resolver.resolve(context, Arrays.asList("testYYY", "testX*"))), equalTo(newHashSet("testXXX", "testXYY", "testYYY")));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testConvertWildcardsOpenClosedIndicesTests() {
|
public void testConvertWildcardsOpenClosedIndicesTests() {
|
||||||
|
@ -129,4 +129,19 @@ public class WildcardExpressionResolverTests extends ESTestCase {
|
||||||
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");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue