From 6d8a85c6af696e94c14a03a823e954c3443f7270 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Thu, 13 Jun 2013 10:11:06 +0200 Subject: [PATCH] Made get mapping rest response consistent. Closes #3172 --- .../mapping/get/RestGetMappingAction.java | 43 +++++-------------- 1 file changed, 11 insertions(+), 32 deletions(-) diff --git a/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/get/RestGetMappingAction.java b/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/get/RestGetMappingAction.java index 4c654b0b34c..3326abafa8f 100644 --- a/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/get/RestGetMappingAction.java +++ b/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/get/RestGetMappingAction.java @@ -31,7 +31,6 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.index.Index; import org.elasticsearch.indices.IndexMissingException; -import org.elasticsearch.indices.TypeMissingException; import org.elasticsearch.rest.*; import org.elasticsearch.rest.action.support.RestXContentBuilder; @@ -82,45 +81,25 @@ public class RestGetMappingAction extends BaseRestHandler { } ImmutableSet uniqueTypes = ImmutableSet.copyOf(types); + for (Map.Entry> indexEntry : mappingsByIndex.entrySet()) { + builder.startObject(indexEntry.getKey(), XContentBuilder.FieldCaseConversion.NONE); - if (indices.length == 1 && uniqueTypes.size() == 1) { - boolean foundType = false; - ImmutableMap indexMetaData = mappingsByIndex.entrySet().iterator().next().getValue(); - for (MappingMetaData mappingMd : indexMetaData.values()) { - if (!uniqueTypes.isEmpty() && !uniqueTypes.contains(mappingMd.type())) { + for (Map.Entry typeEntry : indexEntry.getValue().entrySet()) { + if (!uniqueTypes.isEmpty() && !uniqueTypes.contains(typeEntry.getKey())) { // filter this type out... continue; } foundAny = true; - foundType = true; - builder.field(mappingMd.type()); - builder.map(mappingMd.sourceAsMap()); + builder.field(typeEntry.getKey()); + builder.map(typeEntry.getValue().sourceAsMap()); } - if (!foundType) { - channel.sendResponse(new XContentThrowableRestResponse(request, new TypeMissingException(new Index(indices[0]), uniqueTypes.iterator().next()))); - return; + + if (indexEntry.getValue().isEmpty() && uniqueTypes.isEmpty()) { + // if no types are specified and no mappings are set for the index, consider this an empty mapping + foundAny = true; } - } else { - for (Map.Entry> indexEntry : mappingsByIndex.entrySet()) { - builder.startObject(indexEntry.getKey(), XContentBuilder.FieldCaseConversion.NONE); - for (Map.Entry typeEntry : indexEntry.getValue().entrySet()) { - if (!uniqueTypes.isEmpty() && !uniqueTypes.contains(typeEntry.getKey())) { - // filter this type out... - continue; - } - foundAny = true; - builder.field(typeEntry.getKey()); - builder.map(typeEntry.getValue().sourceAsMap()); - } - - if (indexEntry.getValue().isEmpty() && uniqueTypes.isEmpty()) { - // if no types are specified and no mappings are set for the index, consider this an empty mapping - foundAny = true; - } - - builder.endObject(); - } + builder.endObject(); } builder.endObject();