Add response into ClearScrollResponse
When deleting an individual scroll ID, ES does produce a 200 in the header if successful and a 404 if the scroll ID wasn't found, but returns empty response body. It will be more user friendly to provide some information on whether the scroll deletion is successful.
This commit is contained in:
parent
73f27a3eff
commit
7b5964f9c5
|
@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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<String, Object> 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));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue