mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-17 10:25:15 +00:00
Emit warnings when index templates have multiple mappings (#50982)
Index templates created in the 5x line can still be present in the cluster state through multiple upgrades, and may have more than one mapping defined. 8x will stop supporting templates with multiple mappings, and we should emit deprecation warnings in 7x clusters to give users a chance to update their templates before upgrading.
This commit is contained in:
parent
1536c3e622
commit
0257de8c26
@ -20,6 +20,7 @@ package org.elasticsearch.cluster.metadata;
|
||||
|
||||
import com.carrotsearch.hppc.cursors.ObjectCursor;
|
||||
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.elasticsearch.ElasticsearchParseException;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.AbstractDiffable;
|
||||
@ -32,6 +33,7 @@ import org.elasticsearch.common.collect.MapBuilder;
|
||||
import org.elasticsearch.common.compress.CompressedXContent;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.logging.DeprecationLogger;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.util.set.Sets;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
@ -51,6 +53,8 @@ import java.util.Set;
|
||||
|
||||
public class IndexTemplateMetaData extends AbstractDiffable<IndexTemplateMetaData> {
|
||||
|
||||
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(IndexTemplateMetaData.class));
|
||||
|
||||
private final String name;
|
||||
|
||||
private final int order;
|
||||
@ -97,6 +101,11 @@ public class IndexTemplateMetaData extends AbstractDiffable<IndexTemplateMetaDat
|
||||
this.patterns = patterns;
|
||||
this.settings = settings;
|
||||
this.mappings = mappings;
|
||||
if (this.mappings.size() > 1) {
|
||||
deprecationLogger.deprecatedAndMaybeLog("index-templates",
|
||||
"Index template {} contains multiple typed mappings; templates in 8x will only support a single mapping",
|
||||
name);
|
||||
}
|
||||
this.aliases = aliases;
|
||||
}
|
||||
|
||||
|
@ -32,6 +32,7 @@ import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
@ -168,4 +169,15 @@ public class IndexTemplateMetaDataTests extends ESTestCase {
|
||||
assertThat(parsed, equalTo(template));
|
||||
}
|
||||
}
|
||||
|
||||
public void testDeprecationWarningsOnMultipleMappings() throws IOException {
|
||||
IndexTemplateMetaData.Builder builder = IndexTemplateMetaData.builder("my-template");
|
||||
builder.patterns(Arrays.asList("a", "b"));
|
||||
builder.putMapping("type1", "{\"type1\":{}}");
|
||||
builder.putMapping("type2", "{\"type2\":{}}");
|
||||
builder.build();
|
||||
|
||||
assertWarnings("Index template my-template contains multiple typed mappings; " +
|
||||
"templates in 8x will only support a single mapping");
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user