diff --git a/src/main/java/org/elasticsearch/cluster/metadata/IndexTemplateMetaData.java b/src/main/java/org/elasticsearch/cluster/metadata/IndexTemplateMetaData.java index 6a15044657a..3ab16f53d2e 100644 --- a/src/main/java/org/elasticsearch/cluster/metadata/IndexTemplateMetaData.java +++ b/src/main/java/org/elasticsearch/cluster/metadata/IndexTemplateMetaData.java @@ -303,7 +303,15 @@ public class IndexTemplateMetaData { currentFieldName = parser.currentName(); } else if (token == XContentParser.Token.START_OBJECT) { if ("settings".equals(currentFieldName)) { - builder.settings(ImmutableSettings.settingsBuilder().put(SettingsLoader.Helper.loadNestedFromMap(parser.mapOrdered()))); + ImmutableSettings.Builder templateSettingsBuilder = ImmutableSettings.settingsBuilder(); + for (Map.Entry entry : SettingsLoader.Helper.loadNestedFromMap(parser.mapOrdered()).entrySet()) { + if (!entry.getKey().startsWith("index.")) { + templateSettingsBuilder.put("index." + entry.getKey(), entry.getValue()); + } else { + templateSettingsBuilder.put(entry.getKey(), entry.getValue()); + } + } + builder.settings(templateSettingsBuilder.build()); } else if ("mappings".equals(currentFieldName)) { while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { if (token == XContentParser.Token.FIELD_NAME) { diff --git a/src/test/java/org/elasticsearch/indices/template/IndexTemplateFileLoadingTests.java b/src/test/java/org/elasticsearch/indices/template/IndexTemplateFileLoadingTests.java index 606d78d1666..de451120370 100644 --- a/src/test/java/org/elasticsearch/indices/template/IndexTemplateFileLoadingTests.java +++ b/src/test/java/org/elasticsearch/indices/template/IndexTemplateFileLoadingTests.java @@ -38,7 +38,7 @@ import static org.hamcrest.Matchers.is; /** * */ -@ClusterScope(scope= Scope.SUITE, numNodes=1) +@ClusterScope(scope=Scope.SUITE, numNodes=1) public class IndexTemplateFileLoadingTests extends ElasticsearchIntegrationTest { @Rule @@ -57,7 +57,8 @@ public class IndexTemplateFileLoadingTests extends ElasticsearchIntegrationTest templatesDir.mkdir(); File dst = new File(templatesDir, "template.json"); - String template = Streams.copyToStringFromClasspath("/org/elasticsearch/indices/template/template.json"); + // random template, one uses the 'setting.index.number_of_shards', the other 'settings.number_of_shards' + String template = Streams.copyToStringFromClasspath("/org/elasticsearch/indices/template/template" + randomInt(1) + ".json"); Files.write(template, dst, Charsets.UTF_8); } catch (Exception e) { throw new RuntimeException(e); diff --git a/src/test/java/org/elasticsearch/indices/template/template.json b/src/test/java/org/elasticsearch/indices/template/template0.json similarity index 100% rename from src/test/java/org/elasticsearch/indices/template/template.json rename to src/test/java/org/elasticsearch/indices/template/template0.json diff --git a/src/test/java/org/elasticsearch/indices/template/template1.json b/src/test/java/org/elasticsearch/indices/template/template1.json new file mode 100644 index 00000000000..f91866865e7 --- /dev/null +++ b/src/test/java/org/elasticsearch/indices/template/template1.json @@ -0,0 +1,7 @@ +{ + "template" : "foo*", + "settings" : { + "number_of_shards": 10, + "number_of_replicas": 0 + } +} \ No newline at end of file diff --git a/src/test/java/org/elasticsearch/indices/template/template2.json b/src/test/java/org/elasticsearch/indices/template/template2.json new file mode 100644 index 00000000000..c48169f15a5 --- /dev/null +++ b/src/test/java/org/elasticsearch/indices/template/template2.json @@ -0,0 +1,9 @@ +{ + "template" : "foo*", + "settings" : { + "index" : { + "number_of_shards": 10, + "number_of_replicas": 0 + } + } +} \ No newline at end of file