From ecfe72ebcc27f1c6f120e2e24ce30f3fdebffbff Mon Sep 17 00:00:00 2001 From: Colin Goodheart-Smithe Date: Wed, 7 Jan 2015 11:35:39 +0000 Subject: [PATCH] Indices API: Fix to make GET Index API consistent with docs This fix ensures that calls to the GET alias/mappings/settings/warmers APIs return the aliases/mappings/settings/warmers object even if there is no content within them.. This make them consistent with the GET Index API docs and the breaking changes in 1.4 docs Closes #9148 --- .../test/indices.get_alias/20_empty.yaml | 19 +++++++++++++++++++ .../test/indices.get_mapping/60_empty.yaml | 19 +++++++++++++++++++ .../test/indices.get_warmer/20_empty.yaml | 19 +++++++++++++++++++ .../indices/get/RestGetIndicesAction.java | 12 ++++++------ 4 files changed, 63 insertions(+), 6 deletions(-) create mode 100644 rest-api-spec/test/indices.get_alias/20_empty.yaml create mode 100644 rest-api-spec/test/indices.get_mapping/60_empty.yaml create mode 100644 rest-api-spec/test/indices.get_warmer/20_empty.yaml diff --git a/rest-api-spec/test/indices.get_alias/20_empty.yaml b/rest-api-spec/test/indices.get_alias/20_empty.yaml new file mode 100644 index 00000000000..7405d99441b --- /dev/null +++ b/rest-api-spec/test/indices.get_alias/20_empty.yaml @@ -0,0 +1,19 @@ +--- +setup: + + - do: + indices.create: + index: test_index + + - do: + indices.create: + index: test_index_2 + +--- +"Check empty aliases when getting all aliases via /_alias": + + - do: + indices.get_alias: {} + + - match: {test_index.aliases: {}} + - match: {test_index_2.aliases: {}} diff --git a/rest-api-spec/test/indices.get_mapping/60_empty.yaml b/rest-api-spec/test/indices.get_mapping/60_empty.yaml new file mode 100644 index 00000000000..dfba78578bb --- /dev/null +++ b/rest-api-spec/test/indices.get_mapping/60_empty.yaml @@ -0,0 +1,19 @@ +--- +setup: + + - do: + indices.create: + index: test_1 + + - do: + indices.create: + index: test_2 + +--- +"Check empty mapping when getting all mappings via /_mapping": + + - do: + indices.get_mapping: {} + + - match: { test_1.mappings: {}} + - match: { test_2.mappings: {}} diff --git a/rest-api-spec/test/indices.get_warmer/20_empty.yaml b/rest-api-spec/test/indices.get_warmer/20_empty.yaml new file mode 100644 index 00000000000..702b0cd01d1 --- /dev/null +++ b/rest-api-spec/test/indices.get_warmer/20_empty.yaml @@ -0,0 +1,19 @@ +--- +setup: + + - do: + indices.create: + index: test_1 + + - do: + indices.create: + index: test_2 + +--- +"Check empty warmers when getting all warmers via /_warmer": + + - do: + indices.get_warmer: {} + + - match: { test_1.warmers: {}} + - match: { test_2.warmers: {}} diff --git a/src/main/java/org/elasticsearch/rest/action/admin/indices/get/RestGetIndicesAction.java b/src/main/java/org/elasticsearch/rest/action/admin/indices/get/RestGetIndicesAction.java index be5220cf1a4..dc800f37062 100644 --- a/src/main/java/org/elasticsearch/rest/action/admin/indices/get/RestGetIndicesAction.java +++ b/src/main/java/org/elasticsearch/rest/action/admin/indices/get/RestGetIndicesAction.java @@ -117,24 +117,24 @@ public class RestGetIndicesAction extends BaseRestHandler { } private void writeAliases(ImmutableList aliases, XContentBuilder builder, Params params) throws IOException { + builder.startObject(Fields.ALIASES); if (aliases != null) { - builder.startObject(Fields.ALIASES); for (AliasMetaData alias : aliases) { AliasMetaData.Builder.toXContent(alias, builder, params); } - builder.endObject(); } + builder.endObject(); } private void writeMappings(ImmutableOpenMap mappings, XContentBuilder builder, Params params) throws IOException { + builder.startObject(Fields.MAPPINGS); if (mappings != null) { - builder.startObject(Fields.MAPPINGS); for (ObjectObjectCursor typeEntry : mappings) { builder.field(typeEntry.key); builder.map(typeEntry.value.sourceAsMap()); } - builder.endObject(); } + builder.endObject(); } private void writeSettings(Settings settings, XContentBuilder builder, Params params) throws IOException { @@ -144,13 +144,13 @@ public class RestGetIndicesAction extends BaseRestHandler { } private void writeWarmers(ImmutableList warmers, XContentBuilder builder, Params params) throws IOException { + builder.startObject(Fields.WARMERS); if (warmers != null) { - builder.startObject(Fields.WARMERS); for (IndexWarmersMetaData.Entry warmer : warmers) { IndexWarmersMetaData.FACTORY.toXContent(warmer, builder, params); } - builder.endObject(); } + builder.endObject(); } }); }