use of org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest in project pancm_project by xuwujing.
the class EsHighLevelRestTest1 method getMapping.
private static void getMapping() throws IOException {
String index = "student";
GetMappingsRequest request = new GetMappingsRequest();
request.indices(index);
GetMappingsResponse response = client.indices().getMapping(request, RequestOptions.DEFAULT);
System.out.println("mapping " + response);
System.out.println("mapping " + response.mappings());
response.getMappings().forEach(k -> {
System.out.println("" + k.key);
System.out.println("" + k.value);
System.out.println("" + k.value.get(k.key));
});
}
use of org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest in project canal by alibaba.
the class ESConnection method getMapping.
public MappingMetaData getMapping(String index, String type) {
MappingMetaData mappingMetaData = null;
if (mode == ESClientMode.TRANSPORT) {
ImmutableOpenMap<String, MappingMetaData> mappings;
try {
mappings = transportClient.admin().cluster().prepareState().execute().actionGet().getState().getMetaData().getIndices().get(index).getMappings();
} catch (NullPointerException e) {
throw new IllegalArgumentException("Not found the mapping info of index: " + index);
}
mappingMetaData = mappings.get(type);
} else {
ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings;
try {
GetMappingsRequest request = new GetMappingsRequest();
request.indices(index);
GetMappingsResponse response;
// try {
// response = restHighLevelClient
// .indices()
// .getMapping(request, RequestOptions.DEFAULT);
// // 6.4以下版本直接使用该接口会报错
// } catch (Exception e) {
// logger.warn("Low ElasticSearch version for getMapping");
response = RestHighLevelClientExt.getMapping(restHighLevelClient, 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).get(type);
}
return mappingMetaData;
}
use of org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest in project calcite by apache.
the class Elasticsearch5Schema method getTableMap.
@Override
protected Map<String, Table> getTableMap() {
final ImmutableMap.Builder<String, Table> builder = ImmutableMap.builder();
try {
final GetMappingsResponse response = client.admin().indices().getMappings(new GetMappingsRequest().indices(index)).get();
ImmutableOpenMap<String, MappingMetaData> mapping = response.getMappings().get(index);
for (ObjectObjectCursor<String, MappingMetaData> c : mapping) {
builder.put(c.key, new Elasticsearch5Table(client, index, c.key));
}
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
return builder.build();
}
Aggregations