diff --git a/src/Elasticsearch/Client.php b/src/Elasticsearch/Client.php index c09007121..fc5593899 100644 --- a/src/Elasticsearch/Client.php +++ b/src/Elasticsearch/Client.php @@ -807,6 +807,33 @@ public function index($params) return $endpoint->resultOrFuture($response); } + /** + * $params['refresh'] = (boolean) Should the effected indexes be refreshed? + * ['timeout'] = (time) Time each individual bulk request should wait for shards that are unavailable + * ['consistency'] = (enum) Explicit write consistency setting for the operation + * ['wait_for_completion'] = (boolean) Should the request should block until the reindex is complete + * ['requests_per_second'] = (float) The throttle for this request in sub-requests per second. 0 means set no throttle + * ['body'] = (array) The search definition using the Query DSL and the prototype for the index request (Required) + * + * @param $params array Associative array of parameters + * + * @return array + */ + public function reindex($params) + { + $body = $this->extractArgument($params, 'body'); + + /** @var callback $endpointBuilder */ + $endpointBuilder = $this->endpoints; + /** @var \Elasticsearch\Endpoints\Reindex $endpoint */ + $endpoint = $endpointBuilder('Reindex'); + $endpoint->setBody($body); + $endpoint->setParams($params); + $response = $endpoint->performRequest(); + + return $endpoint->resultOrFuture($response); + } + /** * $params['index'] = (list) A comma-separated list of index names to restrict the operation; use `_all` or empty string to perform the operation on all indices * ['ignore_indices'] = (enum) When performed on multiple indices, allows to ignore `missing` ones diff --git a/src/Elasticsearch/Endpoints/Reindex.php b/src/Elasticsearch/Endpoints/Reindex.php new file mode 100644 index 000000000..13b22f23e --- /dev/null +++ b/src/Elasticsearch/Endpoints/Reindex.php @@ -0,0 +1,63 @@ + + * @license http://www.apache.org/licenses/LICENSE-2.0 Apache2 + * @link http://elasticsearch.org + */ +class Reindex extends AbstractEndpoint +{ + + /** + * @return string[] + */ + protected function getParamWhitelist() + { + return array( + 'refresh', + 'timeout', + 'consistency', + 'wait_for_completion', + 'requests_per_second', + ); + } + + /** + * @return string + */ + protected function getURI() + { + return '/_reindex'; + } + + /** + * @return string + */ + protected function getMethod() + { + return 'POST'; + } + + /** + * @param array $body + * + * @throws \Elasticsearch\Common\Exceptions\InvalidArgumentException + * @return $this + */ + public function setBody($body) + { + if (isset($body) !== true) { + return $this; + } + + $this->body = $body; + + return $this; + } +} \ No newline at end of file