Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the 'template' field in index templates. #49460

Merged
merged 4 commits into from
Jan 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a hard break -- users who specified template in the source would not have seen a deprecation warning about it, since we convert it to index_patterns before sending the REST request to the server. I wasn't sure how to address this, any guidance here would be great.

Copy link
Contributor

@gwbrown gwbrown Nov 22, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can and should add a check to the Deprecation Info API, but that still leaves folks using the OSS distribution lacking a notification.

This comment was based on a misunderstanding, please disregard.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To help clarify my original comment, I am wondering how to warn users of the Java HLRC that they can no longer specify template when using PutIndexTemplateRequest#source. Before this PR we would silently convert it to index_patterns before sending it off to the server.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we change the 7.x branch to add a deprecation warning if template was used and remove it in 8.0? That seems reasonable to me (if possible with the HLRC)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dakrone this is a nice idea, I'll open a follow-up PR against 7.x to emit a deprecation warning if template is used.

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