Skip to content

Commit

Permalink
Add clearScroll method
Browse files Browse the repository at this point in the history
Client was missing the ability to explicitly clear a scroll.  It was
previously possible using the older "scroll=0m" method, but this commit
adds support for explicit clears via Delete.
  • Loading branch information
polyfractal committed Apr 14, 2014
1 parent 9a9e95e commit 9b85c2d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/Elasticsearch/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions src/Elasticsearch/Endpoints/Scroll.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class Scroll extends AbstractEndpoint
// The scroll ID
private $scroll_id;

private $clear = false;


/**
* @param array $body
Expand All @@ -44,6 +46,12 @@ public function setBody($body)
}


public function setClearScroll($clear)
{
$this->clear = $clear;
return $this;
}


/**
* @param $scroll_id
Expand Down Expand Up @@ -94,6 +102,10 @@ protected function getParamWhitelist()
*/
protected function getMethod()
{
if ($this->clear == true) {
return 'DELETE';
}

return 'GET';
}
}

0 comments on commit 9b85c2d

Please sign in to comment.