Skip to content

Commit 2573ba9

Browse files
committed
Improve guidance on removing default mappings. (#54915)
In 7.x, an index template will fail to apply if it contains a `_default_` mapping. Several users have expressed confusion over the fact that loading the template doesn't show any default mappings. This docs change clarifies that in order to see all mappings in the template, you must pass `include_type_name`.
1 parent a6d26f6 commit 2573ba9

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

docs/reference/migration/migrate_7_0/mappings.asciidoc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,20 @@ of `_id`.
3131
The `_default_` mapping has been deprecated in 6.0 and is now no longer allowed
3232
in 7.0. Trying to configure a `_default_` mapping on 7.x indices will result in
3333
an error.
34+
35+
If an index template contains a `_default_` mapping, it will fail to create new
36+
indices. To resolve this issue, the `_default_` mapping should be removed from
37+
the template. Note that in 7.x, the <<indices-get-template, get template API>>
38+
does not show the `_default_` mapping by default, even when it is defined in
39+
the mapping. To see all mappings in the template, the `include_type_name`
40+
parameter must be supplied:
41+
42+
```
43+
GET /_template/my_template?include_type_name
44+
```
45+
46+
For more details on the `include_type_name` parameter and other types-related
47+
API changes, please see <<removal-of-types>>.
3448
//end::notable-breaking-changes[]
3549

3650
[float]

server/src/main/java/org/elasticsearch/index/mapper/MapperService.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ public enum MergeReason {
130130
private static final ObjectHashSet<String> META_FIELDS = ObjectHashSet.from(SORTED_META_FIELDS);
131131

132132
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(MapperService.class));
133+
static final String DEFAULT_MAPPING_ERROR_MESSAGE = "[_default_] mappings are not allowed on new indices and should no " +
134+
"longer be used. See [https://www.elastic.co/guide/en/elasticsearch/reference/current/breaking-changes-7.0.html" +
135+
"#default-mapping-not-allowed] for more information.";
133136

134137
private final IndexAnalyzers indexAnalyzers;
135138

@@ -449,11 +452,9 @@ private synchronized Map<String, DocumentMapper> internalMerge(@Nullable Documen
449452

450453
if (defaultMapper != null) {
451454
if (indexSettings.getIndexVersionCreated().onOrAfter(Version.V_7_0_0)) {
452-
throw new IllegalArgumentException("The [default] mapping cannot be updated on index [" + index().getName() +
453-
"]: defaults mappings are not useful anymore now that indices can have at most one type.");
455+
throw new IllegalArgumentException(DEFAULT_MAPPING_ERROR_MESSAGE);
454456
} else if (reason == MergeReason.MAPPING_UPDATE) { // only log in case of explicit mapping updates
455-
deprecationLogger.deprecated("[_default_] mapping is deprecated since it is not useful anymore now that indexes " +
456-
"cannot have more than one type");
457+
deprecationLogger.deprecated(DEFAULT_MAPPING_ERROR_MESSAGE);
457458
}
458459
assert defaultMapper.type().equals(DEFAULT_MAPPING);
459460
results.put(DEFAULT_MAPPING, defaultMapper);

server/src/test/java/org/elasticsearch/index/mapper/LegacyMapperServiceTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public void testDefaultMappingIsDeprecatedOn6() throws IOException {
8686
}
8787
final MapperService mapperService = createIndex("test", settings).mapperService();
8888
mapperService.merge("_default_", new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE);
89-
assertWarnings("[_default_] mapping is deprecated since it is not useful anymore now that indexes cannot have more than one type");
89+
assertWarnings(MapperService.DEFAULT_MAPPING_ERROR_MESSAGE);
9090
}
9191

9292
}

server/src/test/java/org/elasticsearch/index/mapper/MapperServiceTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,7 @@ public void testDefaultMappingIsRejectedOn7() throws IOException {
313313
MapperService mapperService = createIndex("test").mapperService();
314314
IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
315315
() -> mapperService.merge("_default_", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE));
316-
assertEquals("The [default] mapping cannot be updated on index [test]: defaults mappings are not useful anymore now"
317-
+ " that indices can have at most one type.", e.getMessage());
316+
assertEquals(MapperService.DEFAULT_MAPPING_ERROR_MESSAGE, e.getMessage());
318317
}
319318

320319
public void testFieldNameLengthLimit() throws Throwable {

0 commit comments

Comments
 (0)