Skip to content

Commit

Permalink
Remove the 'template' field in index templates. (#49460)
Browse files Browse the repository at this point in the history
The `template` field was deprecated in 6.0 in favor of `index_patterns`, and can
now be removed.

Relates to #21009.
  • Loading branch information
jtibshirani authored Jan 10, 2020
1 parent a3b851e commit 54f5907
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -278,18 +278,14 @@ public PutIndexTemplateRequest source(Map<String, Object> templateSource) {
Map<String, Object> source = templateSource;
for (Map.Entry<String, Object> 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<String> 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()));
Expand Down
7 changes: 7 additions & 0 deletions docs/reference/migration/migrate_8_0/indices.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -323,14 +323,8 @@ public PutIndexTemplateRequest source(Map<String, Object> templateSource) {
Map<String, Object> source = templateSource;
for (Map.Entry<String, Object> 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<String> elements = ((List<?>) entry.getValue()).stream().map(Object::toString).collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" +
Expand Down

0 comments on commit 54f5907

Please sign in to comment.