es获得所有index和type

1.获得所有index

rest方式:

curl 'localhost:9200/_cat/indices?v'

JAVA方式:

GetIndexResponse response = client.admin().indices().prepareGetIndex().execute().actionGet();
        System.out.println(response.getIndices().length);
        String[] indices = response.getIndices();
        for(String indice : indices){
            System.out.println(indice);
        }

2.获得所有type

rest方式:

curl -XGET 'http://localhost:9200/_mapping?pretty=true'

非格式化:

curl -s -XGET 'http://localhost:9200/_mapping'

JAVA方式:

GetMappingsResponse res = null;
try {
    res = client.admin().indices().getMappings(new GetMappingsRequest().indices(indice)).get();
} catch (InterruptedException e) {
    e.printStackTrace();
} catch (ExecutionException e) {
    e.printStackTrace();
}
ImmutableOpenMap<String, MappingMetaData> mapping  = res.mappings().get(indice);
for (ObjectObjectCursor<String, MappingMetaData> c : mapping) {
    System.out.println("type = "+c.key);
    System.out.println("columns = "+c.value.source());
}

参考

Java API [2.4] » Java API Administration » Indices Administration
Elasticsearch Reference [2.4] » cat APIs
Elasticsearch Reference [2.4] » Indices APIs » Get Mapping
how to get type names of elastic search index in internal java api or jest api

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容