Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the _default_ mapping. #28248

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions docs/reference/indices/put-mapping.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ PUT /twitter-1,twitter-2/_mapping/_doc <1>
<1> Note that the indices specified (`twitter-1,twitter-2`) follows <<multi-index,multiple index names>> and wildcard format.


NOTE: When updating the `_default_` mapping with the
<<indices-put-mapping,PUT mapping>> API, the new mapping is not merged with
the existing mapping. Instead, the new `_default_` mapping replaces the
existing one.

[[updating-field-mappings]]
[float]
=== Updating field mappings
Expand Down
3 changes: 0 additions & 3 deletions docs/reference/mapping/dynamic-mapping.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,3 @@ automatically or explicitly.
include::dynamic/field-mapping.asciidoc[]

include::dynamic/templates.asciidoc[]

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

14 changes: 0 additions & 14 deletions docs/reference/mapping/dynamic/default-mapping.asciidoc

This file was deleted.

12 changes: 12 additions & 0 deletions docs/reference/migration/migrate_7_0/mappings.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@

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

==== The `_default_` mapping is removed

The `_default_` mapping has been deprecated in 6.0 and is now removed in 7.0.
Trying to configure a `_default_` mapping will result in an error.

If an index is created in 6.x with a `_default_` mapping in addition to a
concrete mappings, the `_default_` mapping will be removed on upgrade.

If an index is created in 6.x and only has a `_default_` mapping, which implies
this index is empty as otherwise indexed documents would have implicitly added
a type, then the `_default_` mapping will be renamed to `_doc` on upgrade.

==== `index_options` for numeric fields has been removed

The `index_options` field for numeric fields has been deprecated in 6 and has now been removed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ private Query parentFieldDoToQuery(QueryShardContext context) throws IOException
}

Set<String> childTypes = new HashSet<>();
for (DocumentMapper documentMapper : context.getMapperService().docMappers(false)) {
for (DocumentMapper documentMapper : context.getMapperService().docMappers()) {
ParentFieldMapper parentFieldMapper = documentMapper.parentFieldMapper();
if (parentFieldMapper.active() && type.equals(parentFieldMapper.type())) {
childTypes.add(documentMapper.type());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,43 @@
tasks.get:
wait_for_completion: true
task_id: $task

---
"Create indices that have a default mapping":

- skip:
features: warnings

- do:
warnings:
- "[_default_] mapping is deprecated since it is not useful anymore now that indexes cannot have more than one type"
indices.create:
index: index_with_default_mapping
body:
settings:
index:
number_of_replicas: 0
mappings:
_default_:
properties:
foo:
type: long
my_type:
properties:
bar:
type: keyword

- do:
warnings:
- "[_default_] mapping is deprecated since it is not useful anymore now that indexes cannot have more than one type"
indices.create:
index: index_with_default_mapping2
body:
settings:
index:
number_of_replicas: 0
mappings:
_default_:
properties:
foo:
type: long
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,41 @@
wait_for_completion: true
task_id: $task_id
- match: { task.headers.X-Opaque-Id: "Reindexing Again" }

---
"Verify the indices with a default mapping were upgraded":

- skip:
features: warnings

- do:
indices.get_mapping:
index: index_with_default_mapping

- is_true: index_with_default_mapping.mappings.my_type
- is_false: index_with_default_mapping.mappings._default_

- do:
indices.get_mapping:
index: index_with_default_mapping2

- is_true: index_with_default_mapping2.mappings._doc
- is_false: index_with_default_mapping2.mappings._default_


---
"Verify that we still reject default mappings":

- skip:
features: warnings

- do:
catch: /invalid_type_name_exception/
indices.put_mapping:
index: index_with_default_mapping2
type: _default_
body:
_default_:
properties:
foo:
type: keyword
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,43 @@
properties:
"":
type: keyword

---
"Create index with _default_ mappings":

- skip:
version: " - 6.99.99"
reason: _default_ mapping was removed in 7.0

- do:
catch: /invalid_type_name_exception/
indices.create:
index: test_index
body:
mappings:
_default_:
properties:
foo:
type: keyword

---
"POST _default_ mappings":

- skip:
version: " - 6.99.99"
reason: _default_ mapping was removed in 7.0

- do:
indices.create:
index: test_index

- do:
catch: /invalid_type_name_exception/
indices.put_mapping:
index: test_index
type: _default_
body:
_default_:
properties:
foo:
type: keyword
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ protected void doRun() throws Exception {
case INDEX:
IndexRequest indexRequest = (IndexRequest) docWriteRequest;
final IndexMetaData indexMetaData = metaData.index(concreteIndex);
MappingMetaData mappingMd = indexMetaData.mappingOrDefault(indexRequest.type());
MappingMetaData mappingMd = indexMetaData.mapping(indexRequest.type());
Version indexCreated = indexMetaData.getCreationVersion();
indexRequest.resolveRouting(metaData);
indexRequest.process(indexCreated, mappingMd, concreteIndex.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ static BulkItemResultHolder executeUpdateRequestOnce(UpdateRequest updateRequest
case CREATED:
case UPDATED:
IndexRequest indexRequest = translate.action();
MappingMetaData mappingMd = metaData.mappingOrDefault(indexRequest.type());
MappingMetaData mappingMd = metaData.mapping(indexRequest.type());
indexRequest.process(metaData.getCreationVersion(), mappingMd, concreteIndex);
result = executeIndexRequestOnPrimary(indexRequest, primary, mappingUpdater);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ public void setClient(Client client) {
}

private PutMappingRequestBuilder updateMappingRequest(Index index, String type, Mapping mappingUpdate, final TimeValue timeout) {
if (type.equals(MapperService.DEFAULT_MAPPING)) {
throw new IllegalArgumentException("_default_ mapping should not be updated");
}
return client.preparePutMapping().setConcreteIndex(index).setType(type).setSource(mappingUpdate.toString(), XContentType.JSON)
.setMasterNodeTimeout(timeout).setTimeout(timeout);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.gateway.MetaDataStateFormat;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.rest.RestStatus;
import org.joda.time.DateTime;
Expand Down Expand Up @@ -490,22 +489,6 @@ public Index getResizeSourceIndex() {
? new Index(INDEX_RESIZE_SOURCE_NAME.get(settings), INDEX_RESIZE_SOURCE_UUID.get(settings)) : null;
}

/**
* Sometimes, the default mapping exists and an actual mapping is not created yet (introduced),
* in this case, we want to return the default mapping in case it has some default mapping definitions.
* <p>
* Note, once the mapping type is introduced, the default mapping is applied on the actual typed MappingMetaData,
* setting its routing, timestamp, and so on if needed.
*/
@Nullable
public MappingMetaData mappingOrDefault(String mappingType) {
MappingMetaData mapping = mappings.get(mappingType);
if (mapping != null) {
return mapping;
}
return mappings.get(MapperService.DEFAULT_MAPPING);
}

public ImmutableOpenMap<String, Custom> getCustoms() {
return this.customs;
}
Expand Down Expand Up @@ -914,6 +897,11 @@ public Builder putMapping(MappingMetaData mappingMd) {
return this;
}

public Builder removeMapping(String type) {
mappings.remove(type);
return this;
}

public Builder state(State state) {
this.state = state;
return this;
Expand Down Expand Up @@ -1002,14 +990,6 @@ public IndexMetaData build() {
ImmutableOpenMap.Builder<String, AliasMetaData> tmpAliases = aliases;
Settings tmpSettings = settings;

// update default mapping on the MappingMetaData
if (mappings.containsKey(MapperService.DEFAULT_MAPPING)) {
MappingMetaData defaultMapping = mappings.get(MapperService.DEFAULT_MAPPING);
for (ObjectCursor<MappingMetaData> cursor : mappings.values()) {
cursor.value.updateDefaultMapping(defaultMapping);
}
}

Integer maybeNumberOfShards = settings.getAsInt(SETTING_NUMBER_OF_SHARDS, null);
if (maybeNumberOfShards == null) {
throw new IllegalArgumentException("must specify numberOfShards for index [" + index + "]");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,6 @@ private void initMappers(Map<String, Object> withoutType) {
}
}

void updateDefaultMapping(MappingMetaData defaultMapping) {
if (routing == Routing.EMPTY) {
routing = defaultMapping.routing();
}
}

public String type() {
return this.type;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ public ClusterState execute(ClusterState currentState) throws Exception {

// now, update the mappings with the actual source
Map<String, MappingMetaData> mappingsMetaData = new HashMap<>();
for (DocumentMapper mapper : mapperService.docMappers(true)) {
for (DocumentMapper mapper : mapperService.docMappers()) {
MappingMetaData mappingMd = new MappingMetaData(mapper);
mappingsMetaData.put(mapper.type(), mappingMd);
}
Expand Down Expand Up @@ -660,8 +660,7 @@ static IndexMetaData validateResize(ClusterState state, String sourceIndex,
throw new IllegalStateException("index " + sourceIndex + " must be read-only to resize index. use \"index.blocks.write=true\"");
}

if ((targetIndexMappingsTypes.size() > 1 ||
(targetIndexMappingsTypes.isEmpty() || targetIndexMappingsTypes.contains(MapperService.DEFAULT_MAPPING)) == false)) {
if (targetIndexMappingsTypes.isEmpty() == false) {
throw new IllegalArgumentException("mappings are not allowed when resizing indices" +
", all mappings are copied from the source index");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ public IndexMetaData upgradeIndexMetaData(IndexMetaData indexMetaData, Version m
// we have to run this first otherwise in we try to create IndexSettings
// with broken settings and fail in checkMappingsCompatibility
newMetaData = archiveBrokenIndexSettings(newMetaData);
// remove the _default_ mapping if applicable
newMetaData = MapperService.MAPPINGS_METADATA_6x_UPGRADER.apply(newMetaData);
// only run the check with the upgraded settings!!
checkMappingsCompatibility(newMetaData);
// apply plugin checks
Expand Down
Loading