diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/get/GetSnapshotsRequest.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/get/GetSnapshotsRequest.java index e90f9e578ce37..32c9493b440d5 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/get/GetSnapshotsRequest.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/get/GetSnapshotsRequest.java @@ -37,6 +37,7 @@ public class GetSnapshotsRequest extends MasterNodeRequest public static final String ALL_SNAPSHOTS = "_all"; public static final String CURRENT_SNAPSHOT = "_current"; + public static final boolean DEFAULT_VERBOSE_MODE = true; private String repository; @@ -44,7 +45,7 @@ public class GetSnapshotsRequest extends MasterNodeRequest private boolean ignoreUnavailable; - private boolean verbose = true; + private boolean verbose = DEFAULT_VERBOSE_MODE; public GetSnapshotsRequest() { } diff --git a/core/src/main/java/org/elasticsearch/snapshots/SnapshotInfo.java b/core/src/main/java/org/elasticsearch/snapshots/SnapshotInfo.java index 37cce0ac60174..15741564d39b1 100644 --- a/core/src/main/java/org/elasticsearch/snapshots/SnapshotInfo.java +++ b/core/src/main/java/org/elasticsearch/snapshots/SnapshotInfo.java @@ -21,6 +21,7 @@ import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.Version; import org.elasticsearch.action.ShardOperationFailedException; +import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; @@ -346,6 +347,7 @@ public XContentBuilder toXContent(final XContentBuilder builder, final Params pa return toXContentSnapshot(builder, params); } + final boolean verbose = params.paramAsBoolean("verbose", GetSnapshotsRequest.DEFAULT_VERBOSE_MODE); // write snapshot info for the API and any other situations builder.startObject(); builder.field(SNAPSHOT, snapshotId.getName()); @@ -359,22 +361,22 @@ public XContentBuilder toXContent(final XContentBuilder builder, final Params pa builder.value(index); } builder.endArray(); - if (state != null) { + if (verbose || state != null) { builder.field(STATE, state); } if (reason != null) { builder.field(REASON, reason); } - if (startTime != 0) { + if (verbose || startTime != 0) { builder.field(START_TIME, DATE_TIME_FORMATTER.printer().print(startTime)); builder.field(START_TIME_IN_MILLIS, startTime); } - if (endTime != 0) { + if (verbose || endTime != 0) { builder.field(END_TIME, DATE_TIME_FORMATTER.printer().print(endTime)); builder.field(END_TIME_IN_MILLIS, endTime); builder.timeValueField(DURATION_IN_MILLIS, DURATION, endTime - startTime); } - if (!shardFailures.isEmpty()) { + if (verbose || !shardFailures.isEmpty()) { builder.startArray(FAILURES); for (SnapshotShardFailure shardFailure : shardFailures) { builder.startObject(); @@ -383,7 +385,7 @@ public XContentBuilder toXContent(final XContentBuilder builder, final Params pa } builder.endArray(); } - if (totalShards != 0) { + if (verbose || totalShards != 0) { builder.startObject(SHARDS); builder.field(TOTAL, totalShards); builder.field(FAILED, failedShards()); diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/snapshot.get/10_basic.yaml b/rest-api-spec/src/main/resources/rest-api-spec/test/snapshot.get/10_basic.yaml index 515662355da3e..70008415122d3 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/snapshot.get/10_basic.yaml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/snapshot.get/10_basic.yaml @@ -32,6 +32,7 @@ setup: snapshot: test_snapshot - is_true: snapshots + - is_true: snapshots.0.failures - do: snapshot.delete: @@ -87,6 +88,8 @@ setup: - is_true: snapshots - match: { snapshots.0.snapshot: test_snapshot } - match: { snapshots.0.state: SUCCESS } + - is_false: snapshots.0.failures + - is_false: snapshots.0.shards - is_false: snapshots.0.version - do: