Skip to content

Commit 54f5907

Browse files
authored
Remove the 'template' field in index templates. (#49460)
The `template` field was deprecated in 6.0 in favor of `index_patterns`, and can now be removed. Relates to #21009.
1 parent a3b851e commit 54f5907

File tree

5 files changed

+13
-27
lines changed

5 files changed

+13
-27
lines changed

client/rest-high-level/src/main/java/org/elasticsearch/client/indices/PutIndexTemplateRequest.java

+2-6
Original file line numberDiff line numberDiff line change
@@ -278,18 +278,14 @@ public PutIndexTemplateRequest source(Map<String, Object> templateSource) {
278278
Map<String, Object> source = templateSource;
279279
for (Map.Entry<String, Object> entry : source.entrySet()) {
280280
String name = entry.getKey();
281-
if (name.equals("template")) {
282-
if(entry.getValue() instanceof String) {
283-
patterns(Collections.singletonList((String) entry.getValue()));
284-
}
285-
} else if (name.equals("index_patterns")) {
281+
if (name.equals("index_patterns")) {
286282
if(entry.getValue() instanceof String) {
287283
patterns(Collections.singletonList((String) entry.getValue()));
288284
} else if (entry.getValue() instanceof List) {
289285
List<String> elements = ((List<?>) entry.getValue()).stream().map(Object::toString).collect(Collectors.toList());
290286
patterns(elements);
291287
} else {
292-
throw new IllegalArgumentException("Malformed [template] value, should be a string or a list of strings");
288+
throw new IllegalArgumentException("Malformed [index_patterns] value, should be a string or a list of strings");
293289
}
294290
} else if (name.equals("order")) {
295291
order(XContentMapValues.nodeIntegerValue(entry.getValue(), order()));

docs/reference/migration/migrate_8_0/indices.asciidoc

+7
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,10 @@ The `index.force_memory_term_dictionary` setting was introduced in 7.0 as a
2020
temporary measure to allow users to opt-out of the optimization that leaves the
2121
term dictionary on disk when appropriate. This optimization is now mandatory
2222
and the setting is removed.
23+
24+
[float]
25+
==== Remove support for `template` in put index template requests
26+
27+
In 6.0, we deprecated the `template` field in put index template requests
28+
in favor of using `index_patterns`. Support for the `template` field is now
29+
removed in 8.0.

server/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequest.java

+2-8
Original file line numberDiff line numberDiff line change
@@ -323,14 +323,8 @@ public PutIndexTemplateRequest source(Map<String, Object> templateSource) {
323323
Map<String, Object> source = templateSource;
324324
for (Map.Entry<String, Object> entry : source.entrySet()) {
325325
String name = entry.getKey();
326-
if (name.equals("template")) {
327-
// This is needed to allow for bwc (beats, logstash) with pre-5.0 templates (#21009)
328-
if(entry.getValue() instanceof String) {
329-
deprecationLogger.deprecated("Deprecated field [template] used, replaced by [index_patterns]");
330-
patterns(Collections.singletonList((String) entry.getValue()));
331-
}
332-
} else if (name.equals("index_patterns")) {
333-
if(entry.getValue() instanceof String) {
326+
if (name.equals("index_patterns")) {
327+
if (entry.getValue() instanceof String) {
334328
patterns(Collections.singletonList((String) entry.getValue()));
335329
} else if (entry.getValue() instanceof List) {
336330
List<String> elements = ((List<?>) entry.getValue()).stream().map(Object::toString).collect(Collectors.toList());

server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestPutIndexTemplateAction.java

+1-12
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,9 @@
1919

2020
package org.elasticsearch.rest.action.admin.indices;
2121

22-
import org.apache.logging.log4j.LogManager;
2322
import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest;
2423
import org.elasticsearch.client.node.NodeClient;
2524
import org.elasticsearch.common.Strings;
26-
import org.elasticsearch.common.logging.DeprecationLogger;
2725
import org.elasticsearch.common.xcontent.XContentHelper;
2826
import org.elasticsearch.rest.BaseRestHandler;
2927
import org.elasticsearch.rest.RestController;
@@ -32,14 +30,10 @@
3230

3331
import java.io.IOException;
3432
import java.util.Arrays;
35-
import java.util.Collections;
3633
import java.util.Map;
3734

3835
public class RestPutIndexTemplateAction extends BaseRestHandler {
3936

40-
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(
41-
LogManager.getLogger(RestPutIndexTemplateAction.class));
42-
4337
public RestPutIndexTemplateAction(RestController controller) {
4438
controller.registerHandler(RestRequest.Method.PUT, "/_template/{name}", this);
4539
controller.registerHandler(RestRequest.Method.POST, "/_template/{name}", this);
@@ -54,12 +48,7 @@ public String getName() {
5448
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
5549

5650
PutIndexTemplateRequest putRequest = new PutIndexTemplateRequest(request.param("name"));
57-
if (request.hasParam("template")) {
58-
deprecationLogger.deprecated("Deprecated parameter[template] used, replaced by [index_patterns]");
59-
putRequest.patterns(Collections.singletonList(request.param("template")));
60-
} else {
61-
putRequest.patterns(Arrays.asList(request.paramAsStringArray("index_patterns", Strings.EMPTY_ARRAY)));
62-
}
51+
putRequest.patterns(Arrays.asList(request.paramAsStringArray("index_patterns", Strings.EMPTY_ARRAY)));
6352
putRequest.order(request.paramAsInt("order", putRequest.order()));
6453
putRequest.masterNodeTimeout(request.paramAsTime("master_timeout", putRequest.masterNodeTimeout()));
6554
putRequest.create(request.paramAsBoolean("create", false));

server/src/test/java/org/elasticsearch/indices/template/SimpleIndexTemplateIT.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ public void testIndexTemplateWithAliases() throws Exception {
433433
public void testIndexTemplateWithAliasesInSource() {
434434
client().admin().indices().preparePutTemplate("template_1")
435435
.setSource(new BytesArray("{\n" +
436-
" \"template\" : \"*\",\n" +
436+
" \"index_patterns\" : \"*\",\n" +
437437
" \"aliases\" : {\n" +
438438
" \"my_alias\" : {\n" +
439439
" \"filter\" : {\n" +

0 commit comments

Comments
 (0)