_default_ mapping not applied when using separate master/data nodes
fixes #4124
This commit is contained in:
parent
6bbcc34061
commit
7fc4947271
|
@ -399,6 +399,10 @@ public class MetaDataMappingService extends AbstractComponent {
|
||||||
final IndexMetaData indexMetaData = currentState.metaData().index(index);
|
final IndexMetaData indexMetaData = currentState.metaData().index(index);
|
||||||
IndexService indexService = indicesService.createIndex(indexMetaData.index(), indexMetaData.settings(), clusterService.localNode().id());
|
IndexService indexService = indicesService.createIndex(indexMetaData.index(), indexMetaData.settings(), clusterService.localNode().id());
|
||||||
indicesToClose.add(indexMetaData.index());
|
indicesToClose.add(indexMetaData.index());
|
||||||
|
// make sure to add custom default mapping if exists
|
||||||
|
if (indexMetaData.mappings().containsKey(MapperService.DEFAULT_MAPPING)) {
|
||||||
|
indexService.mapperService().merge(MapperService.DEFAULT_MAPPING, indexMetaData.mappings().get(MapperService.DEFAULT_MAPPING).source().string(), false);
|
||||||
|
}
|
||||||
// only add the current relevant mapping (if exists)
|
// only add the current relevant mapping (if exists)
|
||||||
if (indexMetaData.mappings().containsKey(request.mappingType)) {
|
if (indexMetaData.mappings().containsKey(request.mappingType)) {
|
||||||
indexService.mapperService().merge(request.mappingType, indexMetaData.mappings().get(request.mappingType).source().string(), false);
|
indexService.mapperService().merge(request.mappingType, indexMetaData.mappings().get(request.mappingType).source().string(), false);
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
package org.elasticsearch.cluster;
|
package org.elasticsearch.cluster;
|
||||||
|
|
||||||
|
import org.elasticsearch.cluster.metadata.MappingMetaData;
|
||||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||||
import org.elasticsearch.discovery.MasterNotDiscoveredException;
|
import org.elasticsearch.discovery.MasterNotDiscoveredException;
|
||||||
import org.elasticsearch.test.AbstractIntegrationTest;
|
import org.elasticsearch.test.AbstractIntegrationTest;
|
||||||
|
@ -26,18 +27,19 @@ import org.elasticsearch.test.AbstractIntegrationTest.ClusterScope;
|
||||||
import org.elasticsearch.test.AbstractIntegrationTest.Scope;
|
import org.elasticsearch.test.AbstractIntegrationTest.Scope;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
||||||
import static org.hamcrest.Matchers.nullValue;
|
import static org.hamcrest.Matchers.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ClusterScope(scope = Scope.TEST, numNodes=0)
|
@ClusterScope(scope = Scope.TEST, numNodes = 0)
|
||||||
public class SpecificMasterNodesTests extends AbstractIntegrationTest {
|
public class SpecificMasterNodesTests extends AbstractIntegrationTest {
|
||||||
|
|
||||||
protected final ImmutableSettings.Builder settingsBuilder() {
|
protected final ImmutableSettings.Builder settingsBuilder() {
|
||||||
return ImmutableSettings.builder().put("discovery.type", "zen");
|
return ImmutableSettings.builder().put("discovery.type", "zen");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void simpleOnlyMasterNodeElection() {
|
public void simpleOnlyMasterNodeElection() {
|
||||||
logger.info("--> start data node / non master node");
|
logger.info("--> start data node / non master node");
|
||||||
|
@ -95,4 +97,29 @@ public class SpecificMasterNodesTests extends AbstractIntegrationTest {
|
||||||
assertThat(cluster().nonMasterClient().admin().cluster().prepareState().execute().actionGet().getState().nodes().masterNode().name(), equalTo(nextMasterEligableNodeName));
|
assertThat(cluster().nonMasterClient().admin().cluster().prepareState().execute().actionGet().getState().nodes().masterNode().name(), equalTo(nextMasterEligableNodeName));
|
||||||
assertThat(cluster().masterClient().admin().cluster().prepareState().execute().actionGet().getState().nodes().masterNode().name(), equalTo(nextMasterEligableNodeName));
|
assertThat(cluster().masterClient().admin().cluster().prepareState().execute().actionGet().getState().nodes().masterNode().name(), equalTo(nextMasterEligableNodeName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests that putting custom default mapping and then putting a type mapping will have the default mapping merged
|
||||||
|
* to the type mapping.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testCustomDefaultMapping() throws Exception {
|
||||||
|
logger.info("--> start master node / non data");
|
||||||
|
cluster().startNode(settingsBuilder().put("node.data", false).put("node.master", true));
|
||||||
|
|
||||||
|
logger.info("--> start data node / non master node");
|
||||||
|
cluster().startNode(settingsBuilder().put("node.data", true).put("node.master", false));
|
||||||
|
|
||||||
|
assertAcked(client().admin().indices().prepareCreate("test").setSettings("number_of_shards", 1).get());
|
||||||
|
assertAcked(client().admin().indices().preparePutMapping("test").setType("_default_").setSource("_timestamp", "enabled=true"));
|
||||||
|
|
||||||
|
MappingMetaData defaultMapping = client().admin().cluster().prepareState().get().getState().getMetaData().getIndices().get("test").getMappings().get("_default_");
|
||||||
|
assertThat(defaultMapping.getSourceAsMap().get("_timestamp"), notNullValue());
|
||||||
|
|
||||||
|
assertAcked(client().admin().indices().preparePutMapping("test").setType("_default_").setSource("_timestamp", "enabled=true"));
|
||||||
|
|
||||||
|
assertAcked(client().admin().indices().preparePutMapping("test").setType("type1").setSource("foo", "enabled=true"));
|
||||||
|
MappingMetaData type1Mapping = client().admin().cluster().prepareState().get().getState().getMetaData().getIndices().get("test").getMappings().get("type1");
|
||||||
|
assertThat(type1Mapping.getSourceAsMap().get("_timestamp"), notNullValue());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue