Search in sources :

Example 6 with FieldMappingMetaData

use of org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsResponse.FieldMappingMetaData in project elasticsearch by elastic.

the class TransportGetFieldMappingsIndexAction method shardOperation.

@Override
protected GetFieldMappingsResponse shardOperation(final GetFieldMappingsIndexRequest request, ShardId shardId) {
    assert shardId != null;
    IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex());
    Collection<String> typeIntersection;
    if (request.types().length == 0) {
        typeIntersection = indexService.mapperService().types();
    } else {
        typeIntersection = indexService.mapperService().types().stream().filter(type -> Regex.simpleMatch(request.types(), type)).collect(Collectors.toCollection(ArrayList::new));
        if (typeIntersection.isEmpty()) {
            throw new TypeMissingException(shardId.getIndex(), request.types());
        }
    }
    MapBuilder<String, Map<String, FieldMappingMetaData>> typeMappings = new MapBuilder<>();
    for (String type : typeIntersection) {
        DocumentMapper documentMapper = indexService.mapperService().documentMapper(type);
        Map<String, FieldMappingMetaData> fieldMapping = findFieldMappingsByType(documentMapper, request);
        if (!fieldMapping.isEmpty()) {
            typeMappings.put(type, fieldMapping);
        }
    }
    return new GetFieldMappingsResponse(singletonMap(shardId.getIndexName(), typeMappings.immutableMap()));
}
Also used : IndexService(org.elasticsearch.index.IndexService) FieldMappingMetaData(org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsResponse.FieldMappingMetaData) TypeMissingException(org.elasticsearch.indices.TypeMissingException) DocumentMapper(org.elasticsearch.index.mapper.DocumentMapper) ArrayList(java.util.ArrayList) MapBuilder(org.elasticsearch.common.collect.MapBuilder) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap)

Aggregations

FieldMappingMetaData (org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsResponse.FieldMappingMetaData)6 Map (java.util.Map)3 IOException (java.io.IOException)2 GetFieldMappingsResponse (org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsResponse)2 MapBuilder (org.elasticsearch.common.collect.MapBuilder)2 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)2 ArrayList (java.util.ArrayList)1 Collections.singletonMap (java.util.Collections.singletonMap)1 HashMap (java.util.HashMap)1 ElasticsearchException (org.elasticsearch.ElasticsearchException)1 GetFieldMappingsRequest (org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsRequest)1 PutMappingResponse (org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse)1 IndicesOptions (org.elasticsearch.action.support.IndicesOptions)1 NodeClient (org.elasticsearch.client.node.NodeClient)1 Strings (org.elasticsearch.common.Strings)1 BytesArray (org.elasticsearch.common.bytes.BytesArray)1 BytesStreamOutput (org.elasticsearch.common.io.stream.BytesStreamOutput)1 StreamInput (org.elasticsearch.common.io.stream.StreamInput)1 Settings (org.elasticsearch.common.settings.Settings)1 IndexService (org.elasticsearch.index.IndexService)1