Search in sources :

Example 1 with PutMappingClusterStateUpdateRequest

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);
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) ClusterService(org.elasticsearch.cluster.service.ClusterService) PutMappingClusterStateUpdateRequest(org.elasticsearch.action.admin.indices.mapping.put.PutMappingClusterStateUpdateRequest)

Example 2 with PutMappingClusterStateUpdateRequest

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));
}
Also used : ClusterService(org.elasticsearch.cluster.service.ClusterService) IndexService(org.elasticsearch.index.IndexService) PutMappingClusterStateUpdateRequest(org.elasticsearch.action.admin.indices.mapping.put.PutMappingClusterStateUpdateRequest) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent)

Example 3 with PutMappingClusterStateUpdateRequest

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);
}
Also used : HashMap(java.util.HashMap) PutMappingClusterStateUpdateRequest(org.elasticsearch.action.admin.indices.mapping.put.PutMappingClusterStateUpdateRequest) Index(org.elasticsearch.index.Index) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) Map(java.util.Map) HashMap(java.util.HashMap) MapperService(org.elasticsearch.index.mapper.MapperService)

Aggregations

PutMappingClusterStateUpdateRequest (org.elasticsearch.action.admin.indices.mapping.put.PutMappingClusterStateUpdateRequest)3 ClusterService (org.elasticsearch.cluster.service.ClusterService)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ClusterState (org.elasticsearch.cluster.ClusterState)1 IndexMetadata (org.elasticsearch.cluster.metadata.IndexMetadata)1 CompressedXContent (org.elasticsearch.common.compress.CompressedXContent)1 Index (org.elasticsearch.index.Index)1 IndexService (org.elasticsearch.index.IndexService)1 MapperService (org.elasticsearch.index.mapper.MapperService)1