Fix parsing of file based template loading
We support three different settings in templates * "settings" : { "index" : { "number_of_shards" : 12 } } * "settings" : { "index.number_of_shards" : 12 } * "settings" : { "number_of_shards" : 12 } The latter one was not supported by the fix in #4235 This commit fixes this issue and uses randomized testing to test any of the three cases above when running integration tests. Closes #4411
This commit is contained in:
parent
be860c8004
commit
59cedea010
|
@ -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<String, String> 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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"template" : "foo*",
|
||||
"settings" : {
|
||||
"number_of_shards": 10,
|
||||
"number_of_replicas": 0
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"template" : "foo*",
|
||||
"settings" : {
|
||||
"index" : {
|
||||
"number_of_shards": 10,
|
||||
"number_of_replicas": 0
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue