Unable to create a nested filtered alias on a dataless master

fixes #4112
This commit is contained in:
Shay Banon 2013-11-08 11:22:43 +01:00
parent 7fc4947271
commit 6f286c3382
2 changed files with 21 additions and 1 deletions

View File

@ -37,6 +37,7 @@ import org.elasticsearch.common.util.concurrent.CountDown;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.query.IndexQueryParserService;
import org.elasticsearch.index.service.IndexService;
import org.elasticsearch.indices.IndexMissingException;
@ -115,9 +116,15 @@ public class MetaDataIndexAliasesService extends AbstractComponent {
if (indexService == null) {
indexService = indicesService.indexService(indexMetaData.index());
if (indexService == null) {
// temporarily create the index so we have can parse the filter
// temporarily create the index and add mappings so we have can parse the filter
try {
indexService = indicesService.createIndex(indexMetaData.index(), indexMetaData.settings(), clusterService.localNode().id());
if (indexMetaData.mappings().containsKey(MapperService.DEFAULT_MAPPING)) {
indexService.mapperService().merge(MapperService.DEFAULT_MAPPING, indexMetaData.mappings().get(MapperService.DEFAULT_MAPPING).source().string(), false);
}
for (MappingMetaData mappingMetaData : indexMetaData.mappings().values()) {
indexService.mapperService().merge(mappingMetaData.type(), mappingMetaData.source().string(), false);
}
} catch (Exception e) {
logger.warn("[{}] failed to temporary create in order to apply alias action", e, indexMetaData.index());
continue;

View File

@ -22,6 +22,7 @@ package org.elasticsearch.cluster;
import org.elasticsearch.cluster.metadata.MappingMetaData;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.discovery.MasterNotDiscoveredException;
import org.elasticsearch.index.query.FilterBuilders;
import org.elasticsearch.test.AbstractIntegrationTest;
import org.elasticsearch.test.AbstractIntegrationTest.ClusterScope;
import org.elasticsearch.test.AbstractIntegrationTest.Scope;
@ -122,4 +123,16 @@ public class SpecificMasterNodesTests extends AbstractIntegrationTest {
MappingMetaData type1Mapping = client().admin().cluster().prepareState().get().getState().getMetaData().getIndices().get("test").getMappings().get("type1");
assertThat(type1Mapping.getSourceAsMap().get("_timestamp"), notNullValue());
}
@Test
public void testAliasFilterValidation() 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(prepareCreate("test").addMapping("type1", "{\"type1\" : {\"properties\" : {\"table_a\" : { \"type\" : \"nested\", \"properties\" : {\"field_a\" : { \"type\" : \"string\" },\"field_b\" :{ \"type\" : \"string\" }}}}}}"));
client().admin().indices().prepareAliases().addAlias("test", "a_test", FilterBuilders.nestedFilter("table_a", FilterBuilders.termFilter("table_a.field_b", "y"))).get();
}
}