|
@@ -8,7 +8,10 @@
|
|
|
|
|
|
package org.elasticsearch.index.mapper;
|
|
|
|
|
|
+import org.elasticsearch.Version;
|
|
|
+import org.elasticsearch.common.compress.CompressedXContent;
|
|
|
import org.elasticsearch.core.CheckedConsumer;
|
|
|
+import org.elasticsearch.test.VersionUtils;
|
|
|
import org.elasticsearch.xcontent.XContentBuilder;
|
|
|
|
|
|
import java.io.IOException;
|
|
@@ -25,6 +28,12 @@ public abstract class MetadataMapperTestCase extends MapperServiceTestCase {
|
|
|
|
|
|
protected abstract String fieldName();
|
|
|
|
|
|
+ protected abstract boolean isConfigurable();
|
|
|
+
|
|
|
+ protected boolean isSupportedOn(Version version) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
protected abstract void registerParameters(ParameterChecker checker) throws IOException;
|
|
|
|
|
|
private record ConflictCheck(XContentBuilder init, XContentBuilder update) {}
|
|
@@ -67,6 +76,7 @@ public abstract class MetadataMapperTestCase extends MapperServiceTestCase {
|
|
|
}
|
|
|
|
|
|
public final void testUpdates() throws IOException {
|
|
|
+ assumeTrue("Metadata field " + fieldName() + " isn't configurable", isConfigurable());
|
|
|
ParameterChecker checker = new ParameterChecker();
|
|
|
registerParameters(checker);
|
|
|
for (String param : checker.conflictChecks.keySet()) {
|
|
@@ -92,4 +102,89 @@ public abstract class MetadataMapperTestCase extends MapperServiceTestCase {
|
|
|
updateCheck.check.accept(mapperService.documentMapper());
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public final void testUnsupportedParametersAreRejected() throws IOException {
|
|
|
+ assumeTrue("Metadata field " + fieldName() + " isn't configurable", isConfigurable());
|
|
|
+ Version version = VersionUtils.randomIndexCompatibleVersion(random());
|
|
|
+ assumeTrue("Metadata field " + fieldName() + " is not supported on version " + version, isSupportedOn(version));
|
|
|
+ MapperService mapperService = createMapperService(version, mapping(xContentBuilder -> {}));
|
|
|
+ String mappingAsString = "{\n"
|
|
|
+ + " \"_doc\" : {\n"
|
|
|
+ + " \""
|
|
|
+ + fieldName()
|
|
|
+ + "\" : {\n"
|
|
|
+ + " \"anything\" : \"anything\"\n"
|
|
|
+ + " }\n"
|
|
|
+ + " }\n"
|
|
|
+ + "}";
|
|
|
+ MapperParsingException exception = expectThrows(
|
|
|
+ MapperParsingException.class,
|
|
|
+ () -> mapperService.parseMapping("_doc", new CompressedXContent(mappingAsString))
|
|
|
+ );
|
|
|
+ assertEquals(
|
|
|
+ "Failed to parse mapping: unknown parameter [anything] on metadata field [" + fieldName() + "]",
|
|
|
+ exception.getMessage()
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ public final void testFixedMetaFieldsAreNotConfigurable() throws IOException {
|
|
|
+ assumeFalse("Metadata field " + fieldName() + " is configurable", isConfigurable());
|
|
|
+ Version version = VersionUtils.randomIndexCompatibleVersion(random());
|
|
|
+ assumeTrue("Metadata field " + fieldName() + " is not supported on version " + version, isSupportedOn(version));
|
|
|
+ MapperService mapperService = createMapperService(version, mapping(xContentBuilder -> {}));
|
|
|
+ String mappingAsString = "{\n" + " \"_doc\" : {\n" + " \"" + fieldName() + "\" : {\n" + " }\n" + " }\n" + "}";
|
|
|
+ MapperParsingException exception = expectThrows(
|
|
|
+ MapperParsingException.class,
|
|
|
+ () -> mapperService.parseMapping("_doc", new CompressedXContent(mappingAsString))
|
|
|
+ );
|
|
|
+ assertEquals("Failed to parse mapping: " + fieldName() + " is not configurable", exception.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ public void testTypeAndFriendsAreAcceptedBefore_8_6_0() throws IOException {
|
|
|
+ assumeTrue("Metadata field " + fieldName() + " isn't configurable", isConfigurable());
|
|
|
+ Version previousVersion = VersionUtils.getPreviousVersion(Version.V_8_6_0);
|
|
|
+ Version version = VersionUtils.randomVersionBetween(random(), previousVersion.minimumIndexCompatibilityVersion(), previousVersion);
|
|
|
+ assumeTrue("Metadata field " + fieldName() + " is not supported on version " + version, isSupportedOn(version));
|
|
|
+ MapperService mapperService = createMapperService(version, mapping(b -> {}));
|
|
|
+ // these parameters were previously silently ignored, they will still be ignored in existing indices
|
|
|
+ String[] unsupportedParameters = new String[] { "fields", "copy_to", "boost", "type" };
|
|
|
+ for (String param : unsupportedParameters) {
|
|
|
+ String mappingAsString = "{\n"
|
|
|
+ + " \"_doc\" : {\n"
|
|
|
+ + " \""
|
|
|
+ + fieldName()
|
|
|
+ + "\" : {\n"
|
|
|
+ + " \""
|
|
|
+ + param
|
|
|
+ + "\" : \"any\"\n"
|
|
|
+ + " }\n"
|
|
|
+ + " }\n"
|
|
|
+ + "}";
|
|
|
+ assertNotNull(mapperService.parseMapping("_doc", new CompressedXContent(mappingAsString)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void testTypeAndFriendsAreDeprecatedFrom_8_6_0() throws IOException {
|
|
|
+ assumeTrue("Metadata field " + fieldName() + " isn't configurable", isConfigurable());
|
|
|
+ Version version = VersionUtils.randomVersionBetween(random(), Version.V_8_6_0, Version.CURRENT);
|
|
|
+ assumeTrue("Metadata field " + fieldName() + " is not supported on version " + version, isSupportedOn(version));
|
|
|
+ MapperService mapperService = createMapperService(version, mapping(b -> {}));
|
|
|
+ // these parameters were previously silently ignored, they are now deprecated in new indices
|
|
|
+ String[] unsupportedParameters = new String[] { "fields", "copy_to", "boost", "type" };
|
|
|
+ for (String param : unsupportedParameters) {
|
|
|
+ String mappingAsString = "{\n"
|
|
|
+ + " \"_doc\" : {\n"
|
|
|
+ + " \""
|
|
|
+ + fieldName()
|
|
|
+ + "\" : {\n"
|
|
|
+ + " \""
|
|
|
+ + param
|
|
|
+ + "\" : \"any\"\n"
|
|
|
+ + " }\n"
|
|
|
+ + " }\n"
|
|
|
+ + "}";
|
|
|
+ assertNotNull(mapperService.parseMapping("_doc", new CompressedXContent(mappingAsString)));
|
|
|
+ assertWarnings("Parameter [" + param + "] has no effect on metadata field [" + fieldName() + "] and will be removed in future");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|