Skip to content

Commit 8f9d2ee

Browse files
authored
Reject updates to the _default_ mapping. (#29165)
This will reject mapping updates to the `_default_` mapping with 7.x indices and still emit a deprecation warning with 6.x indices. Relates #15613 Supersedes #28248
1 parent 1d6ed82 commit 8f9d2ee

File tree

14 files changed

+38
-208
lines changed

14 files changed

+38
-208
lines changed

docs/reference/indices/put-mapping.asciidoc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@ PUT /twitter-1,twitter-2/_mapping/_doc <1>
5050
<1> Note that the indices specified (`twitter-1,twitter-2`) follows <<multi-index,multiple index names>> and wildcard format.
5151

5252

53-
NOTE: When updating the `_default_` mapping with the
54-
<<indices-put-mapping,PUT mapping>> API, the new mapping is not merged with
55-
the existing mapping. Instead, the new `_default_` mapping replaces the
56-
existing one.
57-
5853
[[updating-field-mappings]]
5954
[float]
6055
=== Updating field mappings

docs/reference/mapping/dynamic-mapping.asciidoc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,3 @@ include::dynamic/field-mapping.asciidoc[]
3636

3737
include::dynamic/templates.asciidoc[]
3838

39-
include::dynamic/default-mapping.asciidoc[]
40-

docs/reference/mapping/dynamic/default-mapping.asciidoc

Lines changed: 0 additions & 14 deletions
This file was deleted.

docs/reference/migration/migrate_7_0/mappings.asciidoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55

66
The `_all` field deprecated in 6 have now been removed.
77

8+
==== The `_default_` mapping is no longer allowed
9+
10+
The `_default_` mapping has been deprecated in 6.0 and is now no longer allowed
11+
in 7.0. Trying to configure a `_default_` mapping on 7.x indices will result in
12+
an error.
13+
814
==== `index_options` for numeric fields has been removed
915

1016
The `index_options` field for numeric fields has been deprecated in 6 and has now been removed.

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,10 @@ private synchronized Map<String, DocumentMapper> internalMerge(@Nullable Documen
373373
Map<String, DocumentMapper> results = new LinkedHashMap<>(documentMappers.size() + 1);
374374

375375
if (defaultMapper != null) {
376-
if (indexSettings.getIndexVersionCreated().onOrAfter(Version.V_6_0_0_beta1)
377-
&& reason == MergeReason.MAPPING_UPDATE) { // only log in case of explicit mapping updates
376+
if (indexSettings.getIndexVersionCreated().onOrAfter(Version.V_7_0_0_alpha1)) {
377+
throw new IllegalArgumentException("The [default] mapping cannot be updated on index [" + index().getName() +
378+
"]: defaults mappings are not useful anymore now that indices can have at most one type.");
379+
} else if (reason == MergeReason.MAPPING_UPDATE) { // only log in case of explicit mapping updates
378380
DEPRECATION_LOGGER.deprecated("[_default_] mapping is deprecated since it is not useful anymore now that indexes " +
379381
"cannot have more than one type");
380382
}

server/src/main/resources/org/elasticsearch/index/mapper/default-mapping.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

server/src/main/resources/org/elasticsearch/index/mapper/script-mapping.json

Lines changed: 0 additions & 9 deletions
This file was deleted.

server/src/test/java/org/elasticsearch/action/admin/indices/get/GetIndexIT.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,7 @@ private void assertMappings(GetIndexResponse response, String indexName) {
235235
assertThat(mappings.size(), equalTo(1));
236236
ImmutableOpenMap<String, MappingMetaData> indexMappings = mappings.get(indexName);
237237
assertThat(indexMappings, notNullValue());
238-
assertThat(indexMappings.size(), anyOf(equalTo(1), equalTo(2)));
239-
if (indexMappings.size() == 2) {
240-
MappingMetaData mapping = indexMappings.get("_default_");
241-
assertThat(mapping, notNullValue());
242-
}
238+
assertThat(indexMappings.size(), equalTo(1));
243239
MappingMetaData mapping = indexMappings.get("type1");
244240
assertThat(mapping, notNullValue());
245241
assertThat(mapping.type(), equalTo("type1"));
@@ -251,11 +247,7 @@ private void assertEmptyOrOnlyDefaultMappings(GetIndexResponse response, String
251247
assertThat(mappings.size(), equalTo(1));
252248
ImmutableOpenMap<String, MappingMetaData> indexMappings = mappings.get(indexName);
253249
assertThat(indexMappings, notNullValue());
254-
assertThat(indexMappings.size(), anyOf(equalTo(0), equalTo(1)));
255-
if (indexMappings.size() == 1) {
256-
MappingMetaData mapping = indexMappings.get("_default_");
257-
assertThat(mapping, notNullValue());
258-
}
250+
assertThat(indexMappings.size(), equalTo(0));
259251
}
260252

261253
private void assertAliases(GetIndexResponse response, String indexName) {

server/src/test/java/org/elasticsearch/cluster/SpecificMasterNodesIT.java

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -107,32 +107,6 @@ public void testElectOnlyBetweenMasterNodes() throws IOException {
107107
assertThat(internalCluster().masterClient().admin().cluster().prepareState().execute().actionGet().getState().nodes().getMasterNode().getName(), equalTo(nextMasterEligableNodeName));
108108
}
109109

110-
/**
111-
* Tests that putting custom default mapping and then putting a type mapping will have the default mapping merged
112-
* to the type mapping.
113-
*/
114-
public void testCustomDefaultMapping() throws Exception {
115-
logger.info("--> start master node / non data");
116-
internalCluster().startNode(Settings.builder().put(Node.NODE_DATA_SETTING.getKey(), false).put(Node.NODE_MASTER_SETTING.getKey(), true));
117-
118-
logger.info("--> start data node / non master node");
119-
internalCluster().startNode(Settings.builder().put(Node.NODE_DATA_SETTING.getKey(), true).put(Node.NODE_MASTER_SETTING.getKey(), false));
120-
121-
createIndex("test");
122-
assertAcked(client().admin().indices().preparePutMapping("test").setType("_default_").setSource("timestamp", "type=date"));
123-
124-
MappingMetaData defaultMapping = client().admin().cluster().prepareState().get().getState().getMetaData().getIndices().get("test").getMappings().get("_default_");
125-
Map<?,?> properties = (Map<?, ?>) defaultMapping.getSourceAsMap().get("properties");
126-
assertThat(properties.get("timestamp"), notNullValue());
127-
128-
assertAcked(client().admin().indices().preparePutMapping("test").setType("_default_").setSource("timestamp", "type=date"));
129-
130-
assertAcked(client().admin().indices().preparePutMapping("test").setType("type1").setSource("foo", "enabled=true"));
131-
MappingMetaData type1Mapping = client().admin().cluster().prepareState().get().getState().getMetaData().getIndices().get("test").getMappings().get("type1");
132-
properties = (Map<?, ?>) type1Mapping.getSourceAsMap().get("properties");
133-
assertThat(properties.get("timestamp"), notNullValue());
134-
}
135-
136110
public void testAliasFilterValidation() throws Exception {
137111
logger.info("--> start master node / non data");
138112
internalCluster().startNode(Settings.builder().put(Node.NODE_DATA_SETTING.getKey(), false).put(Node.NODE_MASTER_SETTING.getKey(), true));

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,10 @@ public void testTypeNotCreatedOnIndexFailure() throws IOException, InterruptedEx
192192
XContentBuilder mapping = jsonBuilder().startObject().startObject("_default_")
193193
.field("dynamic", "strict")
194194
.endObject().endObject();
195-
createIndex("test", Settings.EMPTY, "_default_", mapping);
195+
Settings settings = Settings.builder()
196+
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_6_3_0)
197+
.build();
198+
createIndex("test", settings, "_default_", mapping);
196199
try {
197200
client().prepareIndex().setIndex("test").setType("type").setSource(jsonBuilder().startObject().field("test", "test").endObject()).get();
198201
fail();

0 commit comments

Comments
 (0)