how to get type names of elastic search index in internal java api or jest api

*爱你&永不变心* 提交于 2019-12-04 18:55:12

问题


I have a index with the name of demo and It contains different types. I'm using elastic search java internal api and rest api jest both of them in my app. Basicly I want to make this request

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

Is there any way to do that especially in jest api? There is no documentation to get mapping for rest client api. What is your suggestion ?


回答1:


This should work, but it's really ugly:

    GetMappingsResponse res = client.admin().indices().getMappings(new GetMappingsRequest().indices("demo")).get();
    ImmutableOpenMap<String, MappingMetaData> mapping  = res.mappings().get("demo");
    for (ObjectObjectCursor<String, MappingMetaData> c : mapping) {
        System.out.println(c.key+" = "+c.value.source());
    }

I don't know if this is officially supported or not -- I just found this by playing around.



来源:https://stackoverflow.com/questions/26543666/how-to-get-type-names-of-elastic-search-index-in-internal-java-api-or-jest-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!