From d90b8148540fae5aadd4be2f05d1e4a519d7fdab Mon Sep 17 00:00:00 2001 From: Julie Tibshirani Date: Thu, 21 Nov 2019 10:58:28 -0800 Subject: [PATCH 1/3] Remove the 'template' field in index templates. The `template` field was deprecated in 6.0 in favor of `index_patterns`, and can now be removed. --- .../client/indices/PutIndexTemplateRequest.java | 8 ++------ .../template/put/PutIndexTemplateRequest.java | 14 ++++---------- .../admin/indices/RestPutIndexTemplateAction.java | 13 +------------ 3 files changed, 7 insertions(+), 28 deletions(-) diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/PutIndexTemplateRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/PutIndexTemplateRequest.java index 2d03a08d2d42c..c5be421ed6fb4 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/PutIndexTemplateRequest.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/PutIndexTemplateRequest.java @@ -278,18 +278,14 @@ public PutIndexTemplateRequest source(Map templateSource) { Map source = templateSource; for (Map.Entry entry : source.entrySet()) { String name = entry.getKey(); - if (name.equals("template")) { - if(entry.getValue() instanceof String) { - patterns(Collections.singletonList((String) entry.getValue())); - } - } else if (name.equals("index_patterns")) { + if (name.equals("index_patterns")) { if(entry.getValue() instanceof String) { patterns(Collections.singletonList((String) entry.getValue())); } else if (entry.getValue() instanceof List) { List elements = ((List) entry.getValue()).stream().map(Object::toString).collect(Collectors.toList()); patterns(elements); } else { - throw new IllegalArgumentException("Malformed [template] value, should be a string or a list of strings"); + throw new IllegalArgumentException("Malformed [index_patterns] value, should be a string or a list of strings"); } } else if (name.equals("order")) { order(XContentMapValues.nodeIntegerValue(entry.getValue(), order())); diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequest.java b/server/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequest.java index 7bcf181a81432..c1bd3983d1cd1 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequest.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequest.java @@ -58,9 +58,9 @@ import java.util.stream.Collectors; import static org.elasticsearch.action.ValidateActions.addValidationError; +import static org.elasticsearch.common.settings.Settings.Builder.EMPTY_SETTINGS; import static org.elasticsearch.common.settings.Settings.readSettingsFromStream; import static org.elasticsearch.common.settings.Settings.writeSettingsToStream; -import static org.elasticsearch.common.settings.Settings.Builder.EMPTY_SETTINGS; /** * A request to create an index template. @@ -326,20 +326,14 @@ public PutIndexTemplateRequest source(Map templateSource) { Map source = templateSource; for (Map.Entry entry : source.entrySet()) { String name = entry.getKey(); - if (name.equals("template")) { - // This is needed to allow for bwc (beats, logstash) with pre-5.0 templates (#21009) - if(entry.getValue() instanceof String) { - deprecationLogger.deprecated("Deprecated field [template] used, replaced by [index_patterns]"); - patterns(Collections.singletonList((String) entry.getValue())); - } - } else if (name.equals("index_patterns")) { - if(entry.getValue() instanceof String) { + if (name.equals("index_patterns")) { + if (entry.getValue() instanceof String) { patterns(Collections.singletonList((String) entry.getValue())); } else if (entry.getValue() instanceof List) { List elements = ((List) entry.getValue()).stream().map(Object::toString).collect(Collectors.toList()); patterns(elements); } else { - throw new IllegalArgumentException("Malformed [template] value, should be a string or a list of strings"); + throw new IllegalArgumentException("Malformed [index_patterns] value, should be a string or a list of strings"); } } else if (name.equals("order")) { order(XContentMapValues.nodeIntegerValue(entry.getValue(), order())); diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestPutIndexTemplateAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestPutIndexTemplateAction.java index 7fe68839d068b..68e62ac3c684f 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestPutIndexTemplateAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestPutIndexTemplateAction.java @@ -19,11 +19,9 @@ package org.elasticsearch.rest.action.admin.indices; -import org.apache.logging.log4j.LogManager; import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; -import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.RestController; @@ -32,14 +30,10 @@ import java.io.IOException; import java.util.Arrays; -import java.util.Collections; import java.util.Map; public class RestPutIndexTemplateAction extends BaseRestHandler { - private static final DeprecationLogger deprecationLogger = new DeprecationLogger( - LogManager.getLogger(RestPutIndexTemplateAction.class)); - public RestPutIndexTemplateAction(RestController controller) { controller.registerHandler(RestRequest.Method.PUT, "/_template/{name}", this); controller.registerHandler(RestRequest.Method.POST, "/_template/{name}", this); @@ -54,12 +48,7 @@ public String getName() { public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { PutIndexTemplateRequest putRequest = new PutIndexTemplateRequest(request.param("name")); - if (request.hasParam("template")) { - deprecationLogger.deprecated("Deprecated parameter[template] used, replaced by [index_patterns]"); - putRequest.patterns(Collections.singletonList(request.param("template"))); - } else { - putRequest.patterns(Arrays.asList(request.paramAsStringArray("index_patterns", Strings.EMPTY_ARRAY))); - } + putRequest.patterns(Arrays.asList(request.paramAsStringArray("index_patterns", Strings.EMPTY_ARRAY))); putRequest.order(request.paramAsInt("order", putRequest.order())); putRequest.masterNodeTimeout(request.paramAsTime("master_timeout", putRequest.masterNodeTimeout())); putRequest.create(request.paramAsBoolean("create", false)); From 52425c51b7b961a9713b15293faf2d73dbaa0c26 Mon Sep 17 00:00:00 2001 From: Julie Tibshirani Date: Thu, 21 Nov 2019 11:27:58 -0800 Subject: [PATCH 2/3] Update the migration documentation. --- docs/reference/migration/migrate_8_0/indices.asciidoc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/reference/migration/migrate_8_0/indices.asciidoc b/docs/reference/migration/migrate_8_0/indices.asciidoc index 49a72352e6354..5b1d5a10df090 100644 --- a/docs/reference/migration/migrate_8_0/indices.asciidoc +++ b/docs/reference/migration/migrate_8_0/indices.asciidoc @@ -20,3 +20,10 @@ The `index.force_memory_term_dictionary` setting was introduced in 7.0 as a temporary measure to allow users to opt-out of the optimization that leaves the term dictionary on disk when appropriate. This optimization is now mandatory and the setting is removed. + +[float] +==== Remove support for `template` in put index template requests + +In 6.0, we deprecated the `template` field in put index template requests +in favor of using `index_patterns`. Support for the `template` field is now +removed in 8.0. From 349fc0b53fbb1d4d38d922b53ff9eae015cf948a Mon Sep 17 00:00:00 2001 From: Julie Tibshirani Date: Thu, 21 Nov 2019 12:05:59 -0800 Subject: [PATCH 3/3] Fix failing test cases. --- .../elasticsearch/indices/template/SimpleIndexTemplateIT.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/test/java/org/elasticsearch/indices/template/SimpleIndexTemplateIT.java b/server/src/test/java/org/elasticsearch/indices/template/SimpleIndexTemplateIT.java index 16924e43aa5a2..2212f6901d739 100644 --- a/server/src/test/java/org/elasticsearch/indices/template/SimpleIndexTemplateIT.java +++ b/server/src/test/java/org/elasticsearch/indices/template/SimpleIndexTemplateIT.java @@ -433,7 +433,7 @@ public void testIndexTemplateWithAliases() throws Exception { public void testIndexTemplateWithAliasesInSource() { client().admin().indices().preparePutTemplate("template_1") .setSource(new BytesArray("{\n" + - " \"template\" : \"*\",\n" + + " \"index_patterns\" : \"*\",\n" + " \"aliases\" : {\n" + " \"my_alias\" : {\n" + " \"filter\" : {\n" +