Search in sources :

Example 1 with GetMappingsResponse

use of org.elasticsearch.client.indices.GetMappingsResponse in project canal by alibaba.

the class ESConnection method getMapping.

public MappingMetaData getMapping(String index) {
    MappingMetaData mappingMetaData = null;
    if (mode == ESClientMode.TRANSPORT) {
        try {
            mappingMetaData = transportClient.admin().cluster().prepareState().execute().actionGet().getState().getMetaData().getIndices().get(index).mapping();
        } catch (NullPointerException e) {
            throw new IllegalArgumentException("Not found the mapping info of index: " + index);
        }
    } else {
        Map<String, MappingMetaData> mappings;
        try {
            GetMappingsRequest request = new GetMappingsRequest();
            request.indices(index);
            GetMappingsResponse response = restHighLevelClient.indices().getMapping(request, RequestOptions.DEFAULT);
            mappings = response.mappings();
        } catch (NullPointerException e) {
            throw new IllegalArgumentException("Not found the mapping info of index: " + index);
        } catch (IOException e) {
            logger.error(e.getMessage(), e);
            return null;
        }
        mappingMetaData = mappings.get(index);
    }
    return mappingMetaData;
}
Also used : IOException(java.io.IOException) MappingMetaData(org.elasticsearch.cluster.metadata.MappingMetaData) GetMappingsRequest(org.elasticsearch.client.indices.GetMappingsRequest) GetMappingsResponse(org.elasticsearch.client.indices.GetMappingsResponse)

Aggregations

IOException (java.io.IOException)1 GetMappingsRequest (org.elasticsearch.client.indices.GetMappingsRequest)1 GetMappingsResponse (org.elasticsearch.client.indices.GetMappingsResponse)1 MappingMetaData (org.elasticsearch.cluster.metadata.MappingMetaData)1