diff --git a/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexTemplateService.java b/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexTemplateService.java index 8d68aba6349..af7f749d2d8 100644 --- a/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexTemplateService.java +++ b/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexTemplateService.java @@ -78,6 +78,11 @@ public class MetaDataIndexTemplateService extends AbstractComponent { } } if (templateNames.isEmpty()) { + // if its a match all pattern, and no templates are found (we have none), don't + // fail with index missing... + if (Regex.isMatchAllPattern(request.name)) { + return currentState; + } throw new IndexTemplateMissingException(request.name); } MetaData.Builder metaData = MetaData.builder().metaData(currentState.metaData()); diff --git a/src/main/java/org/elasticsearch/common/regex/Regex.java b/src/main/java/org/elasticsearch/common/regex/Regex.java index 5925a6cfeef..95b9461d48d 100644 --- a/src/main/java/org/elasticsearch/common/regex/Regex.java +++ b/src/main/java/org/elasticsearch/common/regex/Regex.java @@ -29,11 +29,10 @@ import java.util.regex.Pattern; * */ public class Regex { - + /** * This Regex / {@link Pattern} flag is supported from Java 7 on. * If set on a Java6 JVM the flag will be ignored. - * */ public static final int UNICODE_CHARACTER_CLASS = 0x100; // supported in JAVA7 @@ -44,6 +43,10 @@ public class Regex { return str.indexOf('*') != -1; } + public static boolean isMatchAllPattern(String str) { + return str.equals("*"); + } + /** * Match a String against the given pattern, supporting the following simple * pattern styles: "xxx*", "*xxx", "*xxx*" and "xxx*yyy" matches (with an @@ -179,7 +182,7 @@ public class Regex { } if ((flags & Pattern.COMMENTS) != 0) { sb.append("COMMENTS|"); - } + } if ((flags & UNICODE_CHARACTER_CLASS) != 0) { sb.append("UNICODE_CHAR_CLASS|"); } diff --git a/src/test/java/org/elasticsearch/indices/template/SimpleIndexTemplateTests.java b/src/test/java/org/elasticsearch/indices/template/SimpleIndexTemplateTests.java index ebaa5358374..7b1ba07a4f5 100644 --- a/src/test/java/org/elasticsearch/indices/template/SimpleIndexTemplateTests.java +++ b/src/test/java/org/elasticsearch/indices/template/SimpleIndexTemplateTests.java @@ -20,13 +20,13 @@ package org.elasticsearch.indices.template; import com.google.common.collect.Lists; +import org.elasticsearch.AbstractSharedClusterTest; import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.common.Priority; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.indices.IndexTemplateAlreadyExistsException; -import org.elasticsearch.AbstractSharedClusterTest; import org.junit.Test; import java.util.Arrays; @@ -152,6 +152,10 @@ public class SimpleIndexTemplateTests extends AbstractSharedClusterTest { logger.info("--> delete template*"); admin().indices().prepareDeleteTemplate("template*").execute().actionGet(); assertThat(admin().cluster().prepareState().execute().actionGet().getState().metaData().templates().size(), equalTo(0)); + + logger.info("--> delete * with no templates, make sure we don't get a failure"); + admin().indices().prepareDeleteTemplate("*").execute().actionGet(); + assertThat(admin().cluster().prepareState().execute().actionGet().getState().metaData().templates().size(), equalTo(0)); } @Test