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;
}
Aggregations