问题
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