diff --git a/core/src/main/java/org/elasticsearch/action/search/ClearScrollResponse.java b/core/src/main/java/org/elasticsearch/action/search/ClearScrollResponse.java index ffe476366f7..3540daa255c 100644 --- a/core/src/main/java/org/elasticsearch/action/search/ClearScrollResponse.java +++ b/core/src/main/java/org/elasticsearch/action/search/ClearScrollResponse.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.search; -import org.elasticsearch.Version; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.StatusToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.XContentBuilderString; import org.elasticsearch.rest.RestStatus; import java.io.IOException; @@ -69,6 +69,8 @@ public class ClearScrollResponse extends ActionResponse implements StatusToXCont @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { + builder.field(Fields.SUCCEEDED, succeeded); + builder.field(Fields.NUMFREED, numFreed); return builder; } @@ -85,4 +87,10 @@ public class ClearScrollResponse extends ActionResponse implements StatusToXCont out.writeBoolean(succeeded); out.writeVInt(numFreed); } + + static final class Fields { + static final XContentBuilderString SUCCEEDED = new XContentBuilderString("succeeded"); + static final XContentBuilderString NUMFREED = new XContentBuilderString("num_freed"); + } + } diff --git a/core/src/test/java/org/elasticsearch/search/scroll/SearchScrollIT.java b/core/src/test/java/org/elasticsearch/search/scroll/SearchScrollIT.java index e4e7a69670b..4aeb4161fde 100644 --- a/core/src/test/java/org/elasticsearch/search/scroll/SearchScrollIT.java +++ b/core/src/test/java/org/elasticsearch/search/scroll/SearchScrollIT.java @@ -27,7 +27,10 @@ import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.util.concurrent.UncategorizedExecutionException; +import org.elasticsearch.common.xcontent.ToXContent; +import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.rest.action.search.RestClearScrollAction; @@ -294,6 +297,7 @@ public class SearchScrollIT extends ESIntegTestCase { assertThat(clearResponse.isSucceeded(), is(true)); assertThat(clearResponse.getNumFreed(), greaterThan(0)); assertThat(clearResponse.status(), equalTo(RestStatus.OK)); + assertToXContentResponse(clearResponse, true, clearResponse.getNumFreed()); assertThrows(client().prepareSearchScroll(searchResponse1.getScrollId()).setScroll(TimeValue.timeValueMinutes(2)), RestStatus.NOT_FOUND); assertThrows(client().prepareSearchScroll(searchResponse2.getScrollId()).setScroll(TimeValue.timeValueMinutes(2)), RestStatus.NOT_FOUND); @@ -310,6 +314,7 @@ public class SearchScrollIT extends ESIntegTestCase { assertThat(response.isSucceeded(), is(true)); assertThat(response.getNumFreed(), equalTo(0)); assertThat(response.status(), equalTo(RestStatus.NOT_FOUND)); + assertToXContentResponse(response, true, response.getNumFreed()); } @Test @@ -404,6 +409,7 @@ public class SearchScrollIT extends ESIntegTestCase { assertThat(clearResponse.isSucceeded(), is(true)); assertThat(clearResponse.getNumFreed(), greaterThan(0)); assertThat(clearResponse.status(), equalTo(RestStatus.OK)); + assertToXContentResponse(clearResponse, true, clearResponse.getNumFreed()); assertThrows(internalCluster().transportClient().prepareSearchScroll(searchResponse1.getScrollId()).setScroll(TimeValue.timeValueMinutes(2)), RestStatus.NOT_FOUND); assertThrows(internalCluster().transportClient().prepareSearchScroll(searchResponse2.getScrollId()).setScroll(TimeValue.timeValueMinutes(2)), RestStatus.NOT_FOUND); @@ -593,4 +599,19 @@ public class SearchScrollIT extends ESIntegTestCase { } } + private void assertToXContentResponse(ClearScrollResponse response, boolean succeed, int numFreed) throws IOException { + XContentBuilder builder = XContentFactory.jsonBuilder(); + builder.startObject(); + response.toXContent(builder, ToXContent.EMPTY_PARAMS); + builder.endObject(); + + BytesReference bytesReference = builder.bytes(); + Map map; + try (XContentParser parser = XContentFactory.xContent(bytesReference).createParser(bytesReference)) { + map = parser.map(); + } + + assertThat(map.get("succeeded"), is(succeed)); + assertThat(map.get("num_freed"), equalTo(numFreed)); + } }