|
12 | 12 | import org.elasticsearch.common.compress.CompressedXContent; |
13 | 13 | import org.elasticsearch.core.CheckedConsumer; |
14 | 14 | import org.elasticsearch.index.IndexVersion; |
| 15 | +import org.elasticsearch.index.IndexVersions; |
15 | 16 | import org.elasticsearch.index.mapper.MapperService.MergeReason; |
16 | 17 | import org.elasticsearch.test.index.IndexVersionUtils; |
17 | 18 | import org.elasticsearch.xcontent.XContentBuilder; |
@@ -142,4 +143,88 @@ public final void testFixedMetaFieldsAreNotConfigurable() throws IOException { |
142 | 143 | ); |
143 | 144 | assertEquals("Failed to parse mapping: " + fieldName() + " is not configurable", exception.getMessage()); |
144 | 145 | } |
| 146 | + |
| 147 | + public void testTypeAndFriendsAreAcceptedBefore_8_6_0() throws IOException { |
| 148 | + assumeTrue("Metadata field " + fieldName() + " isn't configurable", isConfigurable()); |
| 149 | + IndexVersion previousVersion = IndexVersionUtils.getPreviousVersion(IndexVersions.V_8_6_0); |
| 150 | + // we randomly also pick read-only versions to test that we can still parse the parameters for them |
| 151 | + IndexVersion version = IndexVersionUtils.randomVersionBetween( |
| 152 | + random(), |
| 153 | + IndexVersionUtils.getLowestReadCompatibleVersion(), |
| 154 | + previousVersion |
| 155 | + ); |
| 156 | + assumeTrue("Metadata field " + fieldName() + " is not supported on version " + version, isSupportedOn(version)); |
| 157 | + MapperService mapperService = createMapperService(version, mapping(b -> {})); |
| 158 | + // these parameters were previously silently ignored, they will still be ignored in existing indices |
| 159 | + String[] unsupportedParameters = new String[] { "fields", "copy_to", "boost", "type" }; |
| 160 | + for (String param : unsupportedParameters) { |
| 161 | + String mappingAsString = "{\n" |
| 162 | + + " \"_doc\" : {\n" |
| 163 | + + " \"" |
| 164 | + + fieldName() |
| 165 | + + "\" : {\n" |
| 166 | + + " \"" |
| 167 | + + param |
| 168 | + + "\" : \"any\"\n" |
| 169 | + + " }\n" |
| 170 | + + " }\n" |
| 171 | + + "}"; |
| 172 | + assertNotNull(mapperService.parseMapping("_doc", MergeReason.MAPPING_UPDATE, new CompressedXContent(mappingAsString))); |
| 173 | + } |
| 174 | + } |
| 175 | + |
| 176 | + public void testTypeAndFriendsAreDeprecatedFrom_8_6_0_TO_9_0_0() throws IOException { |
| 177 | + assumeTrue("Metadata field " + fieldName() + " isn't configurable", isConfigurable()); |
| 178 | + IndexVersion previousVersion = IndexVersionUtils.getPreviousVersion(IndexVersions.UPGRADE_TO_LUCENE_10_0_0); |
| 179 | + IndexVersion version = IndexVersionUtils.randomVersionBetween(random(), IndexVersions.V_8_6_0, previousVersion); |
| 180 | + assumeTrue("Metadata field " + fieldName() + " is not supported on version " + version, isSupportedOn(version)); |
| 181 | + MapperService mapperService = createMapperService(version, mapping(b -> {})); |
| 182 | + // these parameters were deprecated, they now should throw an error in new indices |
| 183 | + String[] unsupportedParameters = new String[] { "fields", "copy_to", "boost", "type" }; |
| 184 | + for (String param : unsupportedParameters) { |
| 185 | + String mappingAsString = "{\n" |
| 186 | + + " \"_doc\" : {\n" |
| 187 | + + " \"" |
| 188 | + + fieldName() |
| 189 | + + "\" : {\n" |
| 190 | + + " \"" |
| 191 | + + param |
| 192 | + + "\" : \"any\"\n" |
| 193 | + + " }\n" |
| 194 | + + " }\n" |
| 195 | + + "}"; |
| 196 | + assertNotNull(mapperService.parseMapping("_doc", MergeReason.MAPPING_UPDATE, new CompressedXContent(mappingAsString))); |
| 197 | + assertWarnings("Parameter [" + param + "] has no effect on metadata field [" + fieldName() + "] and will be removed in future"); |
| 198 | + } |
| 199 | + } |
| 200 | + |
| 201 | + public void testTypeAndFriendsThrow_After_9_0_0() throws IOException { |
| 202 | + assumeTrue("Metadata field " + fieldName() + " isn't configurable", isConfigurable()); |
| 203 | + IndexVersion version = IndexVersionUtils.randomVersionBetween( |
| 204 | + random(), |
| 205 | + IndexVersions.UPGRADE_TO_LUCENE_10_0_0, |
| 206 | + IndexVersion.current() |
| 207 | + ); |
| 208 | + assumeTrue("Metadata field " + fieldName() + " is not supported on version " + version, isSupportedOn(version)); |
| 209 | + MapperService mapperService = createMapperService(version, mapping(b -> {})); |
| 210 | + // these parameters were previously silently ignored, they are now deprecated in new indices |
| 211 | + String[] unsupportedParameters = new String[] { "fields", "copy_to", "boost", "type" }; |
| 212 | + for (String param : unsupportedParameters) { |
| 213 | + String mappingAsString = "{\n" |
| 214 | + + " \"_doc\" : {\n" |
| 215 | + + " \"" |
| 216 | + + fieldName() |
| 217 | + + "\" : {\n" |
| 218 | + + " \"" |
| 219 | + + param |
| 220 | + + "\" : \"any\"\n" |
| 221 | + + " }\n" |
| 222 | + + " }\n" |
| 223 | + + "}"; |
| 224 | + expectThrows( |
| 225 | + MapperParsingException.class, |
| 226 | + () -> mapperService.parseMapping("_doc", MergeReason.MAPPING_UPDATE, new CompressedXContent(mappingAsString)) |
| 227 | + ); |
| 228 | + } |
| 229 | + } |
145 | 230 | } |
0 commit comments