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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容