use of org.elasticsearch.action.admin.indices.mapping.put.PutMappingClusterStateUpdateRequest in project elasticsearch by elastic.
the class MetaDataMappingServiceTests method testClusterStateIsNotChangedWithIdenticalMappings.
public void testClusterStateIsNotChangedWithIdenticalMappings() throws Exception {
createIndex("test", client().admin().indices().prepareCreate("test").addMapping("type"));
final MetaDataMappingService mappingService = getInstanceFromNode(MetaDataMappingService.class);
final ClusterService clusterService = getInstanceFromNode(ClusterService.class);
final PutMappingClusterStateUpdateRequest request = new PutMappingClusterStateUpdateRequest().type("type");
request.source("{ \"properties\" { \"field\": { \"type\": \"string\" }}}");
ClusterState result = mappingService.putMappingExecutor.execute(clusterService.state(), Collections.singletonList(request)).resultingState;
assertFalse(result != clusterService.state());
ClusterState result2 = mappingService.putMappingExecutor.execute(result, Collections.singletonList(request)).resultingState;
assertSame(result, result2);
}
use of org.elasticsearch.action.admin.indices.mapping.put.PutMappingClusterStateUpdateRequest in project elasticsearch by elastic.
the class MetaDataMappingServiceTests method testMappingClusterStateUpdateDoesntChangeExistingIndices.
public void testMappingClusterStateUpdateDoesntChangeExistingIndices() throws Exception {
final IndexService indexService = createIndex("test", client().admin().indices().prepareCreate("test").addMapping("type"));
final CompressedXContent currentMapping = indexService.mapperService().documentMapper("type").mappingSource();
final MetaDataMappingService mappingService = getInstanceFromNode(MetaDataMappingService.class);
final ClusterService clusterService = getInstanceFromNode(ClusterService.class);
// TODO - it will be nice to get a random mapping generator
final PutMappingClusterStateUpdateRequest request = new PutMappingClusterStateUpdateRequest().type("type");
request.source("{ \"properties\" { \"field\": { \"type\": \"string\" }}}");
mappingService.putMappingExecutor.execute(clusterService.state(), Collections.singletonList(request));
assertThat(indexService.mapperService().documentMapper("type").mappingSource(), equalTo(currentMapping));
}
use of org.elasticsearch.action.admin.indices.mapping.put.PutMappingClusterStateUpdateRequest in project crate by crate.
the class AlterTableClusterStateExecutor method updateMapping.
private ClusterState updateMapping(ClusterState currentState, AlterTableRequest request, Index[] concreteIndices) throws Exception {
if (request.mappingDelta() == null) {
return currentState;
}
Map<Index, MapperService> indexMapperServices = new HashMap<>();
Map<String, Object> currentMeta = new HashMap<>();
for (Index index : concreteIndices) {
final IndexMetadata indexMetadata = currentState.metadata().getIndexSafe(index);
Map<String, Object> sourceAsMap = indexMetadata.mapping().sourceAsMap();
Map<String, Object> meta = (Map<String, Object>) sourceAsMap.get("_meta");
if (meta != null) {
Maps.extendRecursive(currentMeta, meta);
}
if (indexMapperServices.containsKey(indexMetadata.getIndex()) == false) {
MapperService mapperService = indicesService.createIndexMapperService(indexMetadata);
indexMapperServices.put(index, mapperService);
// add mappings for all types, we need them for cross-type validation
mapperService.merge(indexMetadata, MapperService.MergeReason.MAPPING_RECOVERY);
}
}
String mappingDelta = addExistingMeta(request, currentMeta);
PutMappingClusterStateUpdateRequest updateRequest = new PutMappingClusterStateUpdateRequest(mappingDelta).ackTimeout(request.timeout()).masterNodeTimeout(request.masterNodeTimeout()).indices(concreteIndices);
return metadataMappingService.putMappingExecutor.applyRequest(currentState, updateRequest, indexMapperServices);
}
Aggregations