diff --git a/server/src/test/java/org/elasticsearch/cluster/metadata/MetaDataMappingServiceTests.java b/server/src/test/java/org/elasticsearch/cluster/metadata/MetaDataMappingServiceTests.java index d7e9767d7a14d..81fd5ec7fc83d 100644 --- a/server/src/test/java/org/elasticsearch/cluster/metadata/MetaDataMappingServiceTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/MetaDataMappingServiceTests.java @@ -26,6 +26,7 @@ import org.elasticsearch.common.compress.CompressedXContent; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexService; +import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESSingleNodeTestCase; import org.elasticsearch.test.InternalSettingsPlugin; @@ -114,4 +115,23 @@ public void testMappingVersionUnchanged() throws Exception { assertThat(result.resultingState.metaData().index("test").getMappingVersion(), equalTo(previousVersion)); } + public void testMappingUpdateAccepts_docAsType() throws Exception { + final IndexService indexService = createIndex("test", + client().admin().indices().prepareCreate("test").addMapping("my_type")); + final MetaDataMappingService mappingService = getInstanceFromNode(MetaDataMappingService.class); + final ClusterService clusterService = getInstanceFromNode(ClusterService.class); + final PutMappingClusterStateUpdateRequest request = new PutMappingClusterStateUpdateRequest() + .type(MapperService.SINGLE_MAPPING_NAME); + request.indices(new Index[] {indexService.index()}); + request.source("{ \"properties\": { \"foo\": { \"type\": \"keyword\" } }}"); + final ClusterStateTaskExecutor.ClusterTasksResult result = + mappingService.putMappingExecutor.execute(clusterService.state(), Collections.singletonList(request)); + assertThat(result.executionResults.size(), equalTo(1)); + assertTrue(result.executionResults.values().iterator().next().isSuccess()); + MappingMetaData mappingMetaData = result.resultingState.metaData().index("test").mapping(); + assertEquals("my_type", mappingMetaData.type()); + assertEquals(Collections.singletonMap("properties", + Collections.singletonMap("foo", + Collections.singletonMap("type", "keyword"))), mappingMetaData.sourceAsMap()); + } }