Mapping: Using _default_ mapping _routing mapping definition fails to apply when introducing type through indexing, closes #1967.
This commit is contained in:
parent
bb0f5cf234
commit
a9e2433dab
|
@ -150,7 +150,7 @@ public class TransportBulkAction extends TransportAction<BulkRequest, BulkRespon
|
|||
|
||||
MappingMetaData mappingMd = null;
|
||||
if (metaData.hasIndex(indexRequest.index())) {
|
||||
mappingMd = metaData.index(indexRequest.index()).mapping(indexRequest.type());
|
||||
mappingMd = metaData.index(indexRequest.index()).mappingOrDefault(indexRequest.type());
|
||||
}
|
||||
indexRequest.process(metaData, aliasOrIndex, mappingMd, allowIdGeneration);
|
||||
} else if (request instanceof DeleteRequest) {
|
||||
|
@ -177,7 +177,7 @@ public class TransportBulkAction extends TransportAction<BulkRequest, BulkRespon
|
|||
list.add(new BulkItemRequest(i, request));
|
||||
} else if (request instanceof DeleteRequest) {
|
||||
DeleteRequest deleteRequest = (DeleteRequest) request;
|
||||
MappingMetaData mappingMd = clusterState.metaData().index(deleteRequest.index()).mapping(deleteRequest.type());
|
||||
MappingMetaData mappingMd = clusterState.metaData().index(deleteRequest.index()).mappingOrDefault(deleteRequest.type());
|
||||
if (mappingMd != null && mappingMd.routing().required() && deleteRequest.routing() == null) {
|
||||
// if routing is required, and no routing on the delete request, we need to broadcast it....
|
||||
GroupShardsIterator groupShards = clusterService.operationRouting().broadcastDeleteShards(clusterState, deleteRequest.index());
|
||||
|
|
|
@ -140,7 +140,7 @@ public class TransportShardBulkAction extends TransportShardReplicationOperation
|
|||
try {
|
||||
|
||||
// validate, if routing is required, that we got routing
|
||||
MappingMetaData mappingMd = clusterState.metaData().index(request.index()).mapping(indexRequest.type());
|
||||
MappingMetaData mappingMd = clusterState.metaData().index(request.index()).mappingOrDefault(indexRequest.type());
|
||||
if (mappingMd != null && mappingMd.routing().required()) {
|
||||
if (indexRequest.routing() == null) {
|
||||
throw new RoutingMissingException(indexRequest.index(), indexRequest.type(), indexRequest.id());
|
||||
|
|
|
@ -102,7 +102,7 @@ public class TransportDeleteAction extends TransportShardReplicationOperationAct
|
|||
request.index(state.metaData().concreteIndex(request.index()));
|
||||
if (state.metaData().hasIndex(request.index())) {
|
||||
// check if routing is required, if so, do a broadcast delete
|
||||
MappingMetaData mappingMd = state.metaData().index(request.index()).mapping(request.type());
|
||||
MappingMetaData mappingMd = state.metaData().index(request.index()).mappingOrDefault(request.type());
|
||||
if (mappingMd != null && mappingMd.routing().required()) {
|
||||
if (request.routing() == null) {
|
||||
indexDeleteAction.execute(new IndexDeleteRequest(request), new ActionListener<IndexDeleteResponse>() {
|
||||
|
|
|
@ -125,7 +125,7 @@ public class TransportIndexAction extends TransportShardReplicationOperationActi
|
|||
request.index(metaData.concreteIndex(request.index()));
|
||||
MappingMetaData mappingMd = null;
|
||||
if (metaData.hasIndex(request.index())) {
|
||||
mappingMd = metaData.index(request.index()).mapping(request.type());
|
||||
mappingMd = metaData.index(request.index()).mappingOrDefault(request.type());
|
||||
}
|
||||
request.process(metaData, aliasOrIndex, mappingMd, allowIdGeneration);
|
||||
return true;
|
||||
|
@ -186,7 +186,7 @@ public class TransportIndexAction extends TransportShardReplicationOperationActi
|
|||
final IndexRequest request = shardRequest.request;
|
||||
|
||||
// validate, if routing is required, that we got routing
|
||||
MappingMetaData mappingMd = clusterState.metaData().index(request.index()).mapping(request.type());
|
||||
MappingMetaData mappingMd = clusterState.metaData().index(request.index()).mappingOrDefault(request.type());
|
||||
if (mappingMd != null && mappingMd.routing().required()) {
|
||||
if (request.routing() == null) {
|
||||
throw new RoutingMissingException(request.index(), request.type(), request.id());
|
||||
|
|
|
@ -40,6 +40,7 @@ import org.elasticsearch.common.xcontent.ToXContent;
|
|||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.index.mapper.MapperService;
|
||||
import org.elasticsearch.rest.RestStatus;
|
||||
import org.elasticsearch.search.warmer.IndexWarmersMetaData;
|
||||
|
||||
|
@ -301,10 +302,27 @@ public class IndexMetaData {
|
|||
return mappings();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public MappingMetaData mapping(String mappingType) {
|
||||
return mappings.get(mappingType);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 ImmutableMap<String, Custom> customs() {
|
||||
return this.customs;
|
||||
}
|
||||
|
@ -503,6 +521,14 @@ public class IndexMetaData {
|
|||
tmpSettings = ImmutableSettings.settingsBuilder().put(settings).putArray("index.aliases").build();
|
||||
}
|
||||
|
||||
// update default mapping on the MappingMetaData
|
||||
if (mappings.containsKey(MapperService.DEFAULT_MAPPING)) {
|
||||
MappingMetaData defaultMapping = mappings.get(MapperService.DEFAULT_MAPPING);
|
||||
for (MappingMetaData mappingMetaData : mappings.map().values()) {
|
||||
mappingMetaData.updateDefaultMapping(defaultMapping);
|
||||
}
|
||||
}
|
||||
|
||||
return new IndexMetaData(index, version, state, tmpSettings, mappings.immutableMap(), tmpAliases.immutableMap(), customs.immutableMap());
|
||||
}
|
||||
|
||||
|
|
|
@ -351,6 +351,18 @@ public class MappingMetaData {
|
|||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
void updateDefaultMapping(MappingMetaData defaultMapping) {
|
||||
if (id == Id.EMPTY) {
|
||||
id = defaultMapping.id();
|
||||
}
|
||||
if (routing == Routing.EMPTY) {
|
||||
routing = defaultMapping.routing();
|
||||
}
|
||||
if (timestamp == Timestamp.EMPTY) {
|
||||
timestamp = defaultMapping.timestamp();
|
||||
}
|
||||
}
|
||||
|
||||
public String type() {
|
||||
return this.type;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue