Allow passing single scrollID in clear scroll API body (#24242)

* Allow single scrollId in string format

Closes #24233
This commit is contained in:
Guillaume Le Floch 2017-04-25 13:43:21 +02:00 committed by Jim Ferenczi
parent 88de33d43d
commit 739cb35d1b
3 changed files with 56 additions and 5 deletions

View File

@ -78,10 +78,17 @@ public class RestClearScrollAction extends BaseRestHandler {
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
if (token == XContentParser.Token.FIELD_NAME) { if (token == XContentParser.Token.FIELD_NAME) {
currentFieldName = parser.currentName(); currentFieldName = parser.currentName();
} else if ("scroll_id".equals(currentFieldName) && token == XContentParser.Token.START_ARRAY) { } else if ("scroll_id".equals(currentFieldName)){
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { if (token == XContentParser.Token.START_ARRAY) {
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
if (token.isValue() == false) {
throw new IllegalArgumentException("scroll_id array element should only contain scroll_id");
}
clearScrollRequest.addScrollId(parser.text());
}
} else {
if (token.isValue() == false) { if (token.isValue() == false) {
throw new IllegalArgumentException("scroll_id array element should only contain scroll_id"); throw new IllegalArgumentException("scroll_id element should only contain scroll_id");
} }
clearScrollRequest.addScrollId(parser.text()); clearScrollRequest.addScrollId(parser.text());
} }

View File

@ -144,7 +144,7 @@ cleared as soon as the scroll is not being used anymore using the
--------------------------------------- ---------------------------------------
DELETE /_search/scroll DELETE /_search/scroll
{ {
"scroll_id" : ["DXF1ZXJ5QW5kRmV0Y2gBAAAAAAAAAD4WYm9laVYtZndUQlNsdDcwakFMNjU1QQ=="] "scroll_id" : "DXF1ZXJ5QW5kRmV0Y2gBAAAAAAAAAD4WYm9laVYtZndUQlNsdDcwakFMNjU1QQ=="
} }
--------------------------------------- ---------------------------------------
// CONSOLE // CONSOLE

View File

@ -38,7 +38,7 @@
scroll_id: $scroll_id1 scroll_id: $scroll_id1
--- ---
"Body params override query string": "Body params with array param override query string":
- do: - do:
indices.create: indices.create:
index: test_scroll index: test_scroll
@ -76,3 +76,47 @@
catch: missing catch: missing
clear_scroll: clear_scroll:
scroll_id: $scroll_id1 scroll_id: $scroll_id1
---
"Body params with string param scroll id override query string":
- skip:
version: " - 5.99.99"
reason: this uses a new API that has been added in 6.0
- 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
scroll: 1m
body:
query:
match_all: {}
- set: {_scroll_id: scroll_id1}
- do:
clear_scroll:
scroll_id: "invalid_scroll_id"
body: { "scroll_id": "$scroll_id1" }
- do:
catch: missing
scroll:
scroll_id: $scroll_id1
- do:
catch: missing
clear_scroll:
scroll_id: $scroll_id1