From 8ddb809f988f2f5abdde831e1c7e1242ae6690e0 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Thu, 12 Sep 2013 10:41:38 +0200 Subject: [PATCH] If all scroll ids should be removed then the `_all` value should be used instead of not specifying any scroll ids. --- docs/reference/search/request/search-type.asciidoc | 9 +++++++-- .../elasticsearch/action/search/ClearScrollRequest.java | 7 ++++++- .../action/search/TransportClearScrollAction.java | 2 +- .../elasticsearch/search/scroll/SearchScrollTests.java | 4 ++-- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/docs/reference/search/request/search-type.asciidoc b/docs/reference/search/request/search-type.asciidoc index bb98ea9ad03..f017892ec6e 100644 --- a/docs/reference/search/request/search-type.asciidoc +++ b/docs/reference/search/request/search-type.asciidoc @@ -142,5 +142,10 @@ resources to keep the view open will cleaned open. Example usage: curl -XDELETE 'localhost:9200/_search/scroll/c2NhbjsxOjBLMzdpWEtqU2IyZHlmVURPeFJOZnc7MzowSzM3aVhLalNiMmR5ZlVET3hSTmZ3OzU6MEszN2lYS2pTYjJkeWZVRE94Uk5mdzsyOjBLMzdpWEtqU2IyZHlmVURPeFJOZnc7NDowSzM3aVhLalNiMmR5ZlVET3hSTmZ3Ow==' -------------------------------------------------- -Multiple scroll ids can be specified in a comma separated manner, if no id is -specified then all scroll ids will be cleared up. \ No newline at end of file +Multiple scroll ids can be specified in a comma separated manner. +If all scroll ids need to be cleared the reserved `_all` value can used instead of an actual `scroll_id`: + +[source,js] +-------------------------------------------------- +curl -XDELETE 'localhost:9200/_search/scroll/_all' +-------------------------------------------------- \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/action/search/ClearScrollRequest.java b/src/main/java/org/elasticsearch/action/search/ClearScrollRequest.java index ad16a546057..75824f85df2 100644 --- a/src/main/java/org/elasticsearch/action/search/ClearScrollRequest.java +++ b/src/main/java/org/elasticsearch/action/search/ClearScrollRequest.java @@ -29,6 +29,7 @@ import java.util.Arrays; import java.util.List; import static com.google.common.collect.Lists.newArrayList; +import static org.elasticsearch.action.ValidateActions.addValidationError; /** */ @@ -53,7 +54,11 @@ public class ClearScrollRequest extends ActionRequest { @Override public ActionRequestValidationException validate() { - return null; + ActionRequestValidationException validationException = null; + if (scrollIds == null || scrollIds.isEmpty()) { + validationException = addValidationError("no scroll ids specified", validationException); + } + return validationException; } @Override diff --git a/src/main/java/org/elasticsearch/action/search/TransportClearScrollAction.java b/src/main/java/org/elasticsearch/action/search/TransportClearScrollAction.java index 396cae028cd..bc662613be0 100644 --- a/src/main/java/org/elasticsearch/action/search/TransportClearScrollAction.java +++ b/src/main/java/org/elasticsearch/action/search/TransportClearScrollAction.java @@ -69,7 +69,7 @@ public class TransportClearScrollAction extends TransportAction listener, ClusterState clusterState) { int expectedOps = 0; this.nodes = clusterState.nodes(); - if (request.getScrollIds() == null || request.getScrollIds().isEmpty()) { + if (request.getScrollIds().size() == 1 && "_all".equals(request.getScrollIds().get(0))) { expectedOps = nodes.size(); } else { for (String parsedScrollId : request.getScrollIds()) { diff --git a/src/test/java/org/elasticsearch/search/scroll/SearchScrollTests.java b/src/test/java/org/elasticsearch/search/scroll/SearchScrollTests.java index d9a2ae50e8c..6e5d02b66cb 100644 --- a/src/test/java/org/elasticsearch/search/scroll/SearchScrollTests.java +++ b/src/test/java/org/elasticsearch/search/scroll/SearchScrollTests.java @@ -19,6 +19,7 @@ package org.elasticsearch.search.scroll; +import org.elasticsearch.AbstractSharedClusterTest; import org.elasticsearch.action.search.ClearScrollResponse; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchType; @@ -27,7 +28,6 @@ import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.sort.SortOrder; -import org.elasticsearch.AbstractSharedClusterTest; import org.junit.Test; import java.util.Map; @@ -367,7 +367,7 @@ public class SearchScrollTests extends AbstractSharedClusterTest { assertThat(((Number) hit.sortValues()[0]).longValue(), equalTo(counter2++)); } - ClearScrollResponse clearResponse = client().prepareClearScroll() + ClearScrollResponse clearResponse = client().prepareClearScroll().addScrollId("_all") .execute().actionGet(); assertThat(clearResponse.isSucceeded(), equalTo(true));