4242import java .io .IOException ;
4343
4444import static org .elasticsearch .rest .RestRequest .Method .GET ;
45+ import static org .elasticsearch .rest .RestRequest .Method .HEAD ;
4546import static org .elasticsearch .rest .RestStatus .OK ;
4647
4748public class RestGetMappingAction extends BaseRestHandler {
48- public RestGetMappingAction (Settings settings , RestController controller ) {
49+
50+ public RestGetMappingAction (final Settings settings , final RestController controller ) {
4951 super (settings );
5052 controller .registerHandler (GET , "/{index}/{type}/_mapping" , this );
5153 controller .registerHandler (GET , "/{index}/_mappings/{type}" , this );
5254 controller .registerHandler (GET , "/{index}/_mapping/{type}" , this );
55+ controller .registerWithDeprecatedHandler (HEAD , "/{index}/_mapping/{type}" , this , HEAD , "/{index}/{type}" , deprecationLogger );
5356 controller .registerHandler (GET , "/_mapping/{type}" , this );
5457 }
5558
5659 @ Override
5760 public RestChannelConsumer prepareRequest (final RestRequest request , final NodeClient client ) throws IOException {
5861 final String [] indices = Strings .splitStringByCommaToArray (request .param ("index" ));
5962 final String [] types = request .paramAsStringArrayOrEmptyIfAll ("type" );
60- GetMappingsRequest getMappingsRequest = new GetMappingsRequest ();
63+ final GetMappingsRequest getMappingsRequest = new GetMappingsRequest ();
6164 getMappingsRequest .indices (indices ).types (types );
6265 getMappingsRequest .indicesOptions (IndicesOptions .fromRequest (request , getMappingsRequest .indicesOptions ()));
6366 getMappingsRequest .local (request .paramAsBoolean ("local" , getMappingsRequest .local ()));
6467 return channel -> client .admin ().indices ().getMappings (getMappingsRequest , new RestBuilderListener <GetMappingsResponse >(channel ) {
6568 @ Override
66- public RestResponse buildResponse (GetMappingsResponse response , XContentBuilder builder ) throws Exception {
67-
68- ImmutableOpenMap <String , ImmutableOpenMap <String , MappingMetaData >> mappingsByIndex = response .getMappings ();
69+ public RestResponse buildResponse (final GetMappingsResponse response , final XContentBuilder builder ) throws Exception {
70+ final ImmutableOpenMap <String , ImmutableOpenMap <String , MappingMetaData >> mappingsByIndex = response .getMappings ();
6971 if (mappingsByIndex .isEmpty ()) {
7072 if (indices .length != 0 && types .length != 0 ) {
7173 return new BytesRestResponse (OK , builder .startObject ().endObject ());
@@ -81,27 +83,28 @@ public RestResponse buildResponse(GetMappingsResponse response, XContentBuilder
8183 }
8284
8385 builder .startObject ();
84- for (ObjectObjectCursor <String , ImmutableOpenMap <String , MappingMetaData >> indexEntry : mappingsByIndex ) {
85- if (indexEntry .value .isEmpty ()) {
86- continue ;
87- }
88- builder .startObject (indexEntry .key );
89- builder .startObject (Fields .MAPPINGS );
90- for (ObjectObjectCursor <String , MappingMetaData > typeEntry : indexEntry .value ) {
91- builder .field (typeEntry .key );
92- builder .map (typeEntry .value .sourceAsMap ());
86+ {
87+ for (final ObjectObjectCursor <String , ImmutableOpenMap <String , MappingMetaData >> indexEntry : mappingsByIndex ) {
88+ if (indexEntry .value .isEmpty ()) {
89+ continue ;
90+ }
91+ builder .startObject (indexEntry .key );
92+ {
93+ builder .startObject ("mappings" );
94+ {
95+ for (final ObjectObjectCursor <String , MappingMetaData > typeEntry : indexEntry .value ) {
96+ builder .field (typeEntry .key , typeEntry .value .sourceAsMap ());
97+ }
98+ }
99+ builder .endObject ();
100+ }
101+ builder .endObject ();
93102 }
94- builder .endObject ();
95- builder .endObject ();
96103 }
97-
98104 builder .endObject ();
99105 return new BytesRestResponse (OK , builder );
100106 }
101107 });
102108 }
103109
104- static class Fields {
105- static final String MAPPINGS = "mappings" ;
106- }
107110}
0 commit comments