[Remove] DynamicTemplate deprecations (#1742)
This commit removes legacy version checks in DynamicTemplate parsing that are no longer valid in OpenSearch 2.0.0. Signed-off-by: Nicholas Walter Knize <nknize@apache.org>
This commit is contained in:
parent
5550f8d7e2
commit
ef44182731
|
@ -32,9 +32,6 @@
|
||||||
|
|
||||||
package org.opensearch.index.mapper;
|
package org.opensearch.index.mapper;
|
||||||
|
|
||||||
import org.opensearch.LegacyESVersion;
|
|
||||||
import org.opensearch.Version;
|
|
||||||
import org.opensearch.common.logging.DeprecationLogger;
|
|
||||||
import org.opensearch.common.regex.Regex;
|
import org.opensearch.common.regex.Regex;
|
||||||
import org.opensearch.common.xcontent.ToXContentObject;
|
import org.opensearch.common.xcontent.ToXContentObject;
|
||||||
import org.opensearch.common.xcontent.XContentBuilder;
|
import org.opensearch.common.xcontent.XContentBuilder;
|
||||||
|
@ -49,8 +46,6 @@ import java.util.TreeMap;
|
||||||
|
|
||||||
public class DynamicTemplate implements ToXContentObject {
|
public class DynamicTemplate implements ToXContentObject {
|
||||||
|
|
||||||
private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(DynamicTemplate.class);
|
|
||||||
|
|
||||||
public enum MatchType {
|
public enum MatchType {
|
||||||
SIMPLE {
|
SIMPLE {
|
||||||
@Override
|
@Override
|
||||||
|
@ -183,7 +178,7 @@ public class DynamicTemplate implements ToXContentObject {
|
||||||
public abstract String defaultMappingType();
|
public abstract String defaultMappingType();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DynamicTemplate parse(String name, Map<String, Object> conf, Version indexVersionCreated) throws MapperParsingException {
|
public static DynamicTemplate parse(String name, Map<String, Object> conf) throws MapperParsingException {
|
||||||
String match = null;
|
String match = null;
|
||||||
String pathMatch = null;
|
String pathMatch = null;
|
||||||
String unmatch = null;
|
String unmatch = null;
|
||||||
|
@ -229,20 +224,18 @@ public class DynamicTemplate implements ToXContentObject {
|
||||||
|
|
||||||
final MatchType matchType = MatchType.fromString(matchPattern);
|
final MatchType matchType = MatchType.fromString(matchPattern);
|
||||||
|
|
||||||
if (indexVersionCreated.onOrAfter(LegacyESVersion.V_6_3_0)) {
|
// Validate the pattern
|
||||||
// Validate that the pattern
|
for (String regex : new String[] { pathMatch, match, pathUnmatch, unmatch }) {
|
||||||
for (String regex : new String[] { pathMatch, match, pathUnmatch, unmatch }) {
|
if (regex == null) {
|
||||||
if (regex == null) {
|
continue;
|
||||||
continue;
|
}
|
||||||
}
|
try {
|
||||||
try {
|
matchType.matches(regex, "");
|
||||||
matchType.matches(regex, "");
|
} catch (IllegalArgumentException e) {
|
||||||
} catch (IllegalArgumentException e) {
|
throw new IllegalArgumentException(
|
||||||
throw new IllegalArgumentException(
|
"Pattern [" + regex + "] of type [" + matchType + "] is invalid. Cannot create dynamic template [" + name + "].",
|
||||||
"Pattern [" + regex + "] of type [" + matchType + "] is invalid. Cannot create dynamic template [" + name + "].",
|
e
|
||||||
e
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -207,7 +207,7 @@ public class RootObjectMapper extends ObjectMapper {
|
||||||
Map.Entry<String, Object> entry = tmpl.entrySet().iterator().next();
|
Map.Entry<String, Object> entry = tmpl.entrySet().iterator().next();
|
||||||
String templateName = entry.getKey();
|
String templateName = entry.getKey();
|
||||||
Map<String, Object> templateParams = (Map<String, Object>) entry.getValue();
|
Map<String, Object> templateParams = (Map<String, Object>) entry.getValue();
|
||||||
DynamicTemplate template = DynamicTemplate.parse(templateName, templateParams, parserContext.indexVersionCreated());
|
DynamicTemplate template = DynamicTemplate.parse(templateName, templateParams);
|
||||||
if (template != null) {
|
if (template != null) {
|
||||||
validateDynamicTemplate(parserContext, template);
|
validateDynamicTemplate(parserContext, template);
|
||||||
templates.add(template);
|
templates.add(template);
|
||||||
|
|
|
@ -32,8 +32,6 @@
|
||||||
|
|
||||||
package org.opensearch.index.mapper;
|
package org.opensearch.index.mapper;
|
||||||
|
|
||||||
import org.opensearch.LegacyESVersion;
|
|
||||||
import org.opensearch.Version;
|
|
||||||
import org.opensearch.common.Strings;
|
import org.opensearch.common.Strings;
|
||||||
import org.opensearch.common.xcontent.ToXContent;
|
import org.opensearch.common.xcontent.ToXContent;
|
||||||
import org.opensearch.common.xcontent.XContentBuilder;
|
import org.opensearch.common.xcontent.XContentBuilder;
|
||||||
|
@ -53,10 +51,7 @@ public class DynamicTemplateTests extends OpenSearchTestCase {
|
||||||
templateDef.put("mapping", Collections.singletonMap("store", true));
|
templateDef.put("mapping", Collections.singletonMap("store", true));
|
||||||
templateDef.put("random_param", "random_value");
|
templateDef.put("random_param", "random_value");
|
||||||
|
|
||||||
IllegalArgumentException e = expectThrows(
|
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> DynamicTemplate.parse("my_template", templateDef));
|
||||||
IllegalArgumentException.class,
|
|
||||||
() -> DynamicTemplate.parse("my_template", templateDef, Version.CURRENT.minimumIndexCompatibilityVersion())
|
|
||||||
);
|
|
||||||
assertEquals("Illegal dynamic template parameter: [random_param]", e.getMessage());
|
assertEquals("Illegal dynamic template parameter: [random_param]", e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,10 +60,7 @@ public class DynamicTemplateTests extends OpenSearchTestCase {
|
||||||
templateDef2.put("match_mapping_type", "text");
|
templateDef2.put("match_mapping_type", "text");
|
||||||
templateDef2.put("mapping", Collections.singletonMap("store", true));
|
templateDef2.put("mapping", Collections.singletonMap("store", true));
|
||||||
// if a wrong match type is specified, we ignore the template
|
// if a wrong match type is specified, we ignore the template
|
||||||
IllegalArgumentException e = expectThrows(
|
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> DynamicTemplate.parse("my_template", templateDef2));
|
||||||
IllegalArgumentException.class,
|
|
||||||
() -> DynamicTemplate.parse("my_template", templateDef2, Version.CURRENT.minimumIndexCompatibilityVersion())
|
|
||||||
);
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"No field type matched on [text], possible values are [object, string, long, double, boolean, date, binary]",
|
"No field type matched on [text], possible values are [object, string, long, double, boolean, date, binary]",
|
||||||
e.getMessage()
|
e.getMessage()
|
||||||
|
@ -84,7 +76,7 @@ public class DynamicTemplateTests extends OpenSearchTestCase {
|
||||||
templateDef.put("mapping", Collections.singletonMap("store", true));
|
templateDef.put("mapping", Collections.singletonMap("store", true));
|
||||||
IllegalArgumentException e = expectThrows(
|
IllegalArgumentException e = expectThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
() -> DynamicTemplate.parse("my_template", templateDef, LegacyESVersion.V_6_3_0)
|
() -> DynamicTemplate.parse("my_template", templateDef)
|
||||||
);
|
);
|
||||||
assertEquals("Pattern [*a] of type [regex] is invalid. Cannot create dynamic template [my_template].", e.getMessage());
|
assertEquals("Pattern [*a] of type [regex] is invalid. Cannot create dynamic template [my_template].", e.getMessage());
|
||||||
}
|
}
|
||||||
|
@ -94,7 +86,7 @@ public class DynamicTemplateTests extends OpenSearchTestCase {
|
||||||
Map<String, Object> templateDef = new HashMap<>();
|
Map<String, Object> templateDef = new HashMap<>();
|
||||||
templateDef.put("match_mapping_type", "*");
|
templateDef.put("match_mapping_type", "*");
|
||||||
templateDef.put("mapping", Collections.singletonMap("store", true));
|
templateDef.put("mapping", Collections.singletonMap("store", true));
|
||||||
DynamicTemplate template = DynamicTemplate.parse("my_template", templateDef, Version.CURRENT.minimumIndexCompatibilityVersion());
|
DynamicTemplate template = DynamicTemplate.parse("my_template", templateDef);
|
||||||
assertTrue(template.match("a.b", "b", randomFrom(XContentFieldType.values())));
|
assertTrue(template.match("a.b", "b", randomFrom(XContentFieldType.values())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,7 +94,7 @@ public class DynamicTemplateTests extends OpenSearchTestCase {
|
||||||
Map<String, Object> templateDef = new HashMap<>();
|
Map<String, Object> templateDef = new HashMap<>();
|
||||||
templateDef.put("match_mapping_type", "string");
|
templateDef.put("match_mapping_type", "string");
|
||||||
templateDef.put("mapping", Collections.singletonMap("store", true));
|
templateDef.put("mapping", Collections.singletonMap("store", true));
|
||||||
DynamicTemplate template = DynamicTemplate.parse("my_template", templateDef, Version.CURRENT.minimumIndexCompatibilityVersion());
|
DynamicTemplate template = DynamicTemplate.parse("my_template", templateDef);
|
||||||
assertTrue(template.match("a.b", "b", XContentFieldType.STRING));
|
assertTrue(template.match("a.b", "b", XContentFieldType.STRING));
|
||||||
assertFalse(template.match("a.b", "b", XContentFieldType.BOOLEAN));
|
assertFalse(template.match("a.b", "b", XContentFieldType.BOOLEAN));
|
||||||
}
|
}
|
||||||
|
@ -112,7 +104,7 @@ public class DynamicTemplateTests extends OpenSearchTestCase {
|
||||||
Map<String, Object> templateDef = new HashMap<>();
|
Map<String, Object> templateDef = new HashMap<>();
|
||||||
templateDef.put("match_mapping_type", "string");
|
templateDef.put("match_mapping_type", "string");
|
||||||
templateDef.put("mapping", Collections.singletonMap("store", true));
|
templateDef.put("mapping", Collections.singletonMap("store", true));
|
||||||
DynamicTemplate template = DynamicTemplate.parse("my_template", templateDef, Version.CURRENT.minimumIndexCompatibilityVersion());
|
DynamicTemplate template = DynamicTemplate.parse("my_template", templateDef);
|
||||||
XContentBuilder builder = JsonXContent.contentBuilder();
|
XContentBuilder builder = JsonXContent.contentBuilder();
|
||||||
template.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
template.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||||
assertEquals("{\"match_mapping_type\":\"string\",\"mapping\":{\"store\":true}}", Strings.toString(builder));
|
assertEquals("{\"match_mapping_type\":\"string\",\"mapping\":{\"store\":true}}", Strings.toString(builder));
|
||||||
|
@ -122,7 +114,7 @@ public class DynamicTemplateTests extends OpenSearchTestCase {
|
||||||
templateDef.put("match", "*name");
|
templateDef.put("match", "*name");
|
||||||
templateDef.put("unmatch", "first_name");
|
templateDef.put("unmatch", "first_name");
|
||||||
templateDef.put("mapping", Collections.singletonMap("store", true));
|
templateDef.put("mapping", Collections.singletonMap("store", true));
|
||||||
template = DynamicTemplate.parse("my_template", templateDef, Version.CURRENT.minimumIndexCompatibilityVersion());
|
template = DynamicTemplate.parse("my_template", templateDef);
|
||||||
builder = JsonXContent.contentBuilder();
|
builder = JsonXContent.contentBuilder();
|
||||||
template.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
template.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||||
assertEquals("{\"match\":\"*name\",\"unmatch\":\"first_name\",\"mapping\":{\"store\":true}}", Strings.toString(builder));
|
assertEquals("{\"match\":\"*name\",\"unmatch\":\"first_name\",\"mapping\":{\"store\":true}}", Strings.toString(builder));
|
||||||
|
@ -132,7 +124,7 @@ public class DynamicTemplateTests extends OpenSearchTestCase {
|
||||||
templateDef.put("path_match", "*name");
|
templateDef.put("path_match", "*name");
|
||||||
templateDef.put("path_unmatch", "first_name");
|
templateDef.put("path_unmatch", "first_name");
|
||||||
templateDef.put("mapping", Collections.singletonMap("store", true));
|
templateDef.put("mapping", Collections.singletonMap("store", true));
|
||||||
template = DynamicTemplate.parse("my_template", templateDef, Version.CURRENT.minimumIndexCompatibilityVersion());
|
template = DynamicTemplate.parse("my_template", templateDef);
|
||||||
builder = JsonXContent.contentBuilder();
|
builder = JsonXContent.contentBuilder();
|
||||||
template.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
template.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||||
assertEquals("{\"path_match\":\"*name\",\"path_unmatch\":\"first_name\",\"mapping\":{\"store\":true}}", Strings.toString(builder));
|
assertEquals("{\"path_match\":\"*name\",\"path_unmatch\":\"first_name\",\"mapping\":{\"store\":true}}", Strings.toString(builder));
|
||||||
|
@ -142,7 +134,7 @@ public class DynamicTemplateTests extends OpenSearchTestCase {
|
||||||
templateDef.put("match", "^a$");
|
templateDef.put("match", "^a$");
|
||||||
templateDef.put("match_pattern", "regex");
|
templateDef.put("match_pattern", "regex");
|
||||||
templateDef.put("mapping", Collections.singletonMap("store", true));
|
templateDef.put("mapping", Collections.singletonMap("store", true));
|
||||||
template = DynamicTemplate.parse("my_template", templateDef, Version.CURRENT.minimumIndexCompatibilityVersion());
|
template = DynamicTemplate.parse("my_template", templateDef);
|
||||||
builder = JsonXContent.contentBuilder();
|
builder = JsonXContent.contentBuilder();
|
||||||
template.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
template.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||||
assertEquals("{\"match\":\"^a$\",\"match_pattern\":\"regex\",\"mapping\":{\"store\":true}}", Strings.toString(builder));
|
assertEquals("{\"match\":\"^a$\",\"match_pattern\":\"regex\",\"mapping\":{\"store\":true}}", Strings.toString(builder));
|
||||||
|
|
Loading…
Reference in New Issue