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

IndexMetaData#mappingOrDefault doesn't need to take a type argument. #37480

Merged
merged 2 commits into from
Jan 16, 2019
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,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.mappingOrDefault();
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 @@ -191,7 +191,7 @@ static void executeBulkItemRequest(BulkPrimaryExecutionContext context, UpdateHe
case UPDATED:
IndexRequest indexRequest = updateResult.action();
IndexMetaData metaData = context.getPrimary().indexSettings().getIndexMetaData();
MappingMetaData mappingMd = metaData.mappingOrDefault(indexRequest.type());
MappingMetaData mappingMd = metaData.mappingOrDefault();
indexRequest.process(metaData.getCreationVersion(), mappingMd, updateRequest.concreteIndex());
context.setRequestToExecute(indexRequest);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,12 +505,15 @@ public Index getResizeSourceIndex() {
* 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;
public MappingMetaData mappingOrDefault() {
MappingMetaData mapping = null;
for (ObjectCursor<MappingMetaData> m : mappings.values()) {
if (mapping == null || mapping.type().equals(MapperService.DEFAULT_MAPPING)) {
mapping = m.value;
}
}
return mappings.get(MapperService.DEFAULT_MAPPING);

return mapping;
}

ImmutableOpenMap<String, DiffableStringMap> getCustomData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.elasticsearch.cluster.metadata;

import org.elasticsearch.Version;
import org.elasticsearch.action.admin.indices.rollover.MaxAgeCondition;
import org.elasticsearch.action.admin.indices.rollover.MaxDocsCondition;
import org.elasticsearch.action.admin.indices.rollover.MaxSizeCondition;
Expand All @@ -39,6 +40,7 @@
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.indices.IndicesModule;
import org.elasticsearch.test.ESTestCase;
Expand Down Expand Up @@ -287,4 +289,38 @@ public void testNumberOfRoutingShards() {
() -> IndexMetaData.INDEX_NUMBER_OF_ROUTING_SHARDS_SETTING.get(notAFactorySettings));
assertEquals("the number of source shards [2] must be a factor of [3]", iae.getMessage());
}

public void testMappingOrDefault() throws IOException {
Settings settings = Settings.builder()
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 2)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1)
.build();
IndexMetaData meta = IndexMetaData.builder("index")
.settings(settings)
.build();
assertNull(meta.mappingOrDefault());

meta = IndexMetaData.builder("index")
.settings(settings)
.putMapping("type", "{}")
.build();
assertNotNull(meta.mappingOrDefault());
assertEquals("type", meta.mappingOrDefault().type());

meta = IndexMetaData.builder("index")
.settings(settings)
.putMapping(MapperService.DEFAULT_MAPPING, "{}")
.build();
assertNotNull(meta.mappingOrDefault());
assertEquals(MapperService.DEFAULT_MAPPING, meta.mappingOrDefault().type());

meta = IndexMetaData.builder("index")
.settings(settings)
.putMapping("type", "{}")
.putMapping(MapperService.DEFAULT_MAPPING, "{}")
.build();
assertNotNull(meta.mappingOrDefault());
assertEquals("type", meta.mappingOrDefault().type());
}
}