diff --git a/src/Elasticsearch/Client.php b/src/Elasticsearch/Client.php index aa2d1e0cf..da90d8f77 100644 --- a/src/Elasticsearch/Client.php +++ b/src/Elasticsearch/Client.php @@ -1068,6 +1068,35 @@ public function scroll($params = array()) } + /** + * $params['scroll_id'] = (string) The scroll ID for scrolled search + * ['scroll'] = (duration) Specify how long a consistent view of the index should be maintained for scrolled search + * ['body'] = (string) The scroll ID for scrolled search + * + * @param $params array Associative array of parameters + * + * @return array + */ + public function clearScroll($params = array()) + { + $scrollID = $this->extractArgument($params, 'scroll_id'); + + $body = $this->extractArgument($params, 'body'); + + /** @var callback $endpointBuilder */ + $endpointBuilder = $this->dicEndpoints; + + /** @var \Elasticsearch\Endpoints\Scroll $endpoint */ + $endpoint = $endpointBuilder('Scroll'); + $endpoint->setScrollID($scrollID) + ->setBody($body) + ->setClearScroll(true); + $endpoint->setParams($params); + $response = $endpoint->performRequest(); + return $response['data']; + } + + /** * $params['id'] = (string) Document ID (Required) * ['index'] = (string) The name of the index (Required) diff --git a/src/Elasticsearch/Endpoints/Scroll.php b/src/Elasticsearch/Endpoints/Scroll.php index b2cf2b5db..6ae4c9e91 100644 --- a/src/Elasticsearch/Endpoints/Scroll.php +++ b/src/Elasticsearch/Endpoints/Scroll.php @@ -25,6 +25,8 @@ class Scroll extends AbstractEndpoint // The scroll ID private $scroll_id; + private $clear = false; + /** * @param array $body @@ -44,6 +46,12 @@ public function setBody($body) } + public function setClearScroll($clear) + { + $this->clear = $clear; + return $this; + } + /** * @param $scroll_id @@ -94,6 +102,10 @@ protected function getParamWhitelist() */ protected function getMethod() { + if ($this->clear == true) { + return 'DELETE'; + } + return 'GET'; } } \ No newline at end of file