- 查看集羣信息(索引分片,副本數,創建時間等信息):curl -XGET "http://127.0.0.1:9200/index1-mdl/_settings?pretty"
- java實現方式
public Map<String, String> getIndexSettings(String indexName) {
Settings stat = EsClient.getInstance().getEsClient()
.admin()
.cluster()
.prepareState()
.execute()
.actionGet()
.getState()
.getMetaData()
.getIndices()
.get(indexName)
.getSettings();
return stat.getAsMap();
}
- 獲取索引中所有的字段及類型:curl -XGET "http://127.0.0.1:9200/index1-mdl/_mapping?pretty"
1. java實現方式
public Map<String, Object> getIndexMappings(String indexName) {
GetMappingsRequest getMappingsRequest = new GetMappingsRequest();
getMappingsRequest.indices(indexName).types(new String[0]);
GetMappingsResponse response = EsClient.getInstance().getEsClient()
.admin()
.indices()
.getMappings(getMappingsRequest)
.actionGet();
ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings = response.getMappings();
if (mappings.size() == 1) {
for (ObjectObjectCursor<String, ImmutableOpenMap<String, MappingMetaData>> indexEntry : mappings) {
if (indexEntry.value.isEmpty()) {
continue;
}
for (ObjectObjectCursor<String, MappingMetaData> typeEntry : indexEntry.value) {
// System.out.println(typeEntry.value.sourceAsMap());
Map<String, Object> filedNameAndTypeMap;
try {
filedNameAndTypeMap = typeEntry.value.sourceAsMap();
} catch (IOException e) {
throw new RuntimeException(e);
}
return filedNameAndTypeMap;
}
}
}
return null;
}