The clear scroll apis now optionally accepts a scroll_id in it body.

Closes #5726
This commit is contained in:
Martijn van Groningen 2014-04-08 20:41:32 +07:00
parent c4a49c2488
commit b400129597
3 changed files with 42 additions and 1 deletions

View File

@ -14,6 +14,8 @@
},
"params": {}
},
"body": null
"body": {
"description": "A comma-separated list of scroll IDs to clear if none was specified via the scroll_id parameter"
}
}
}

View File

@ -0,0 +1,35 @@
---
"Clear scroll":
- do:
indices.create:
index: test_scroll
- do:
index:
index: test_scroll
type: test
id: 42
body: { foo: bar }
- do:
indices.refresh: {}
- do:
search:
index: test_scroll
search_type: scan
scroll: 1m
body:
query:
match_all: {}
- set: {_scroll_id: scroll_id1}
- do:
clear_scroll:
scroll_id: $scroll_id1
- do:
scroll:
scroll_id: $scroll_id1
- length: {hits.hits: 0}

View File

@ -27,6 +27,7 @@ import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.rest.*;
import org.elasticsearch.rest.action.support.RestActions;
import org.elasticsearch.rest.action.support.RestBuilderListener;
import java.util.Arrays;
@ -49,6 +50,9 @@ public class RestClearScrollAction extends BaseRestHandler {
@Override
public void handleRequest(final RestRequest request, final RestChannel channel) {
String scrollIds = request.param("scroll_id");
if (scrollIds == null) {
scrollIds = RestActions.getRestContent(request).toUtf8();
}
ClearScrollRequest clearRequest = new ClearScrollRequest();
clearRequest.setScrollIds(Arrays.asList(splitScrollIds(scrollIds)));