Skip to content

Commit

Permalink
Add Reindex endpoing
Browse files Browse the repository at this point in the history
* add reindex function
* fix namespace and comment for reindex api
  • Loading branch information
Nexucis authored and polyfractal committed May 6, 2016
1 parent 6a868ea commit d2484c7
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/Elasticsearch/Client.php
Expand Up @@ -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
Expand Down
63 changes: 63 additions & 0 deletions src/Elasticsearch/Endpoints/Reindex.php
@@ -0,0 +1,63 @@
<?php

namespace Elasticsearch\Endpoints;

/**
* Class Reindex
*
* @category Elasticsearch
* @package Elasticsearch\Endpoints\Indices
* @author Augustin Husson <husson.augustin@gmail.com>
* @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;
}
}

0 comments on commit d2484c7

Please sign in to comment.