|
@@ -20,12 +20,16 @@
|
|
|
package org.elasticsearch.index.mapper;
|
|
|
|
|
|
import org.apache.lucene.index.IndexOptions;
|
|
|
+import org.elasticsearch.Version;
|
|
|
+import org.elasticsearch.cluster.metadata.IndexMetaData;
|
|
|
import org.elasticsearch.common.Strings;
|
|
|
import org.elasticsearch.common.bytes.BytesReference;
|
|
|
import org.elasticsearch.common.compress.CompressedXContent;
|
|
|
+import org.elasticsearch.common.settings.Settings;
|
|
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
|
|
import org.elasticsearch.common.xcontent.XContentType;
|
|
|
import org.elasticsearch.test.ESSingleNodeTestCase;
|
|
|
+import org.elasticsearch.test.VersionUtils;
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Collections;
|
|
@@ -95,33 +99,33 @@ public class FieldNamesFieldMapperTests extends ESSingleNodeTestCase {
|
|
|
assertFieldNames(Collections.emptySet(), doc);
|
|
|
}
|
|
|
|
|
|
- public void testExplicitEnabled() throws Exception {
|
|
|
+ public void testUsingEnabledSettingThrows() throws Exception {
|
|
|
String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type")
|
|
|
.startObject("_field_names").field("enabled", true).endObject()
|
|
|
.startObject("properties")
|
|
|
.startObject("field").field("type", "keyword").field("doc_values", false).endObject()
|
|
|
.endObject().endObject().endObject());
|
|
|
- DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser()
|
|
|
- .parse("type", new CompressedXContent(mapping));
|
|
|
- FieldNamesFieldMapper fieldNamesMapper = docMapper.metadataMapper(FieldNamesFieldMapper.class);
|
|
|
- assertTrue(fieldNamesMapper.fieldType().isEnabled());
|
|
|
+ MapperParsingException ex = expectThrows(MapperParsingException.class,
|
|
|
+ () -> createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping)));
|
|
|
|
|
|
- ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "1",
|
|
|
- BytesReference.bytes(XContentFactory.jsonBuilder()
|
|
|
- .startObject()
|
|
|
- .field("field", "value")
|
|
|
- .endObject()),
|
|
|
- XContentType.JSON));
|
|
|
-
|
|
|
- assertFieldNames(set("field"), doc);
|
|
|
- assertWarnings(FieldNamesFieldMapper.TypeParser.ENABLED_DEPRECATION_MESSAGE.replace("{}", "test"));
|
|
|
+ assertEquals("The `enabled` setting for the `_field_names` field has been deprecated and removed but is still used in index [{}]. "
|
|
|
+ + "Please remove it from your mappings and templates.", ex.getMessage());
|
|
|
}
|
|
|
|
|
|
- public void testDisabled() throws Exception {
|
|
|
+ /**
|
|
|
+ * disabling the _field_names should still work for indices before 8.0
|
|
|
+ */
|
|
|
+ public void testUsingEnabledBefore8() throws Exception {
|
|
|
String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type")
|
|
|
.startObject("_field_names").field("enabled", false).endObject()
|
|
|
.endObject().endObject());
|
|
|
- DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser()
|
|
|
+
|
|
|
+ DocumentMapper docMapper = createIndex("test",
|
|
|
+ Settings.builder()
|
|
|
+ .put(IndexMetaData.SETTING_INDEX_VERSION_CREATED.getKey(),
|
|
|
+ VersionUtils.randomPreviousCompatibleVersion(random(), Version.V_8_0_0))
|
|
|
+ .build()).mapperService()
|
|
|
+ .documentMapperParser()
|
|
|
.parse("type", new CompressedXContent(mapping));
|
|
|
FieldNamesFieldMapper fieldNamesMapper = docMapper.metadataMapper(FieldNamesFieldMapper.class);
|
|
|
assertFalse(fieldNamesMapper.fieldType().isEnabled());
|
|
@@ -137,14 +141,20 @@ public class FieldNamesFieldMapperTests extends ESSingleNodeTestCase {
|
|
|
assertWarnings(FieldNamesFieldMapper.TypeParser.ENABLED_DEPRECATION_MESSAGE.replace("{}", "test"));
|
|
|
}
|
|
|
|
|
|
- public void testMergingMappings() throws Exception {
|
|
|
+ /**
|
|
|
+ * Merging the "_field_names" enabled setting is forbidden in 8.0, but we still want to tests the behavior on pre-8 indices
|
|
|
+ */
|
|
|
+ public void testMergingMappingsBefore8() throws Exception {
|
|
|
String enabledMapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type")
|
|
|
.startObject("_field_names").field("enabled", true).endObject()
|
|
|
.endObject().endObject());
|
|
|
String disabledMapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type")
|
|
|
.startObject("_field_names").field("enabled", false).endObject()
|
|
|
.endObject().endObject());
|
|
|
- MapperService mapperService = createIndex("test").mapperService();
|
|
|
+ MapperService mapperService = createIndex("test", Settings.builder()
|
|
|
+ .put(IndexMetaData.SETTING_INDEX_VERSION_CREATED.getKey(),
|
|
|
+ VersionUtils.randomPreviousCompatibleVersion(random(), Version.V_8_0_0))
|
|
|
+ .build()).mapperService();
|
|
|
|
|
|
DocumentMapper mapperEnabled = mapperService.merge("type", new CompressedXContent(enabledMapping),
|
|
|
MapperService.MergeReason.MAPPING_UPDATE);
|
|
@@ -156,4 +166,12 @@ public class FieldNamesFieldMapperTests extends ESSingleNodeTestCase {
|
|
|
assertTrue(mapperEnabled.metadataMapper(FieldNamesFieldMapper.class).fieldType().isEnabled());
|
|
|
assertWarnings(FieldNamesFieldMapper.TypeParser.ENABLED_DEPRECATION_MESSAGE.replace("{}", "test"));
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected boolean forbidPrivateIndexSettings() {
|
|
|
+ /**
|
|
|
+ * This is needed to force the index version with {@link IndexMetaData.SETTING_INDEX_VERSION_CREATED}.
|
|
|
+ */
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|