9

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 seems to be no documentation to get mapping for rest client api. What should I do?

Braiam
  • 1
  • 11
  • 47
  • 78
Haktan Aydın
  • 581
  • 1
  • 6
  • 21

1 Answers1

12

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.

Braiam
  • 1
  • 11
  • 47
  • 78
Alcanzar
  • 16,985
  • 6
  • 42
  • 59
  • Thank you for reply. Yes It is really interesting and worked for internal java api. If you have any idea for doing this with jest api, can you share with me ? Actually using jest api to this work is more important than internal java api for my app. – Haktan Aydın Oct 24 '14 at 14:47
  • Unfortunately prior to your post, I'd never heard of the Jest API. – Alcanzar Oct 24 '14 at 15:04
  • 2
    Based on just looking at their github site, it looks like it would be something like `GetMapping get = new GetMapping.Builder("demo").build(); res = client.execute(get)` – Alcanzar Oct 24 '14 at 15:17
  • GetMapping get = new GetMapping.Builder().addIndex("demo").build(); JestResult jestResult = jestClient.execute(get); System.out.println(jestResult.getJsonString()); – Haktan Aydın Oct 25 '14 at 08:15