Skip to content

Commit d2484c7

Browse files
Nexucispolyfractal
authored andcommitted
Add Reindex endpoing
* add reindex function * fix namespace and comment for reindex api
1 parent 6a868ea commit d2484c7

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

src/Elasticsearch/Client.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,33 @@ public function index($params)
807807
return $endpoint->resultOrFuture($response);
808808
}
809809

810+
/**
811+
* $params['refresh'] = (boolean) Should the effected indexes be refreshed?
812+
* ['timeout'] = (time) Time each individual bulk request should wait for shards that are unavailable
813+
* ['consistency'] = (enum) Explicit write consistency setting for the operation
814+
* ['wait_for_completion'] = (boolean) Should the request should block until the reindex is complete
815+
* ['requests_per_second'] = (float) The throttle for this request in sub-requests per second. 0 means set no throttle
816+
* ['body'] = (array) The search definition using the Query DSL and the prototype for the index request (Required)
817+
*
818+
* @param $params array Associative array of parameters
819+
*
820+
* @return array
821+
*/
822+
public function reindex($params)
823+
{
824+
$body = $this->extractArgument($params, 'body');
825+
826+
/** @var callback $endpointBuilder */
827+
$endpointBuilder = $this->endpoints;
828+
/** @var \Elasticsearch\Endpoints\Reindex $endpoint */
829+
$endpoint = $endpointBuilder('Reindex');
830+
$endpoint->setBody($body);
831+
$endpoint->setParams($params);
832+
$response = $endpoint->performRequest();
833+
834+
return $endpoint->resultOrFuture($response);
835+
}
836+
810837
/**
811838
* $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
812839
* ['ignore_indices'] = (enum) When performed on multiple indices, allows to ignore `missing` ones
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
namespace Elasticsearch\Endpoints;
4+
5+
/**
6+
* Class Reindex
7+
*
8+
* @category Elasticsearch
9+
* @package Elasticsearch\Endpoints\Indices
10+
* @author Augustin Husson <husson.augustin@gmail.com>
11+
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache2
12+
* @link http://elasticsearch.org
13+
*/
14+
class Reindex extends AbstractEndpoint
15+
{
16+
17+
/**
18+
* @return string[]
19+
*/
20+
protected function getParamWhitelist()
21+
{
22+
return array(
23+
'refresh',
24+
'timeout',
25+
'consistency',
26+
'wait_for_completion',
27+
'requests_per_second',
28+
);
29+
}
30+
31+
/**
32+
* @return string
33+
*/
34+
protected function getURI()
35+
{
36+
return '/_reindex';
37+
}
38+
39+
/**
40+
* @return string
41+
*/
42+
protected function getMethod()
43+
{
44+
return 'POST';
45+
}
46+
47+
/**
48+
* @param array $body
49+
*
50+
* @throws \Elasticsearch\Common\Exceptions\InvalidArgumentException
51+
* @return $this
52+
*/
53+
public function setBody($body)
54+
{
55+
if (isset($body) !== true) {
56+
return $this;
57+
}
58+
59+
$this->body = $body;
60+
61+
return $this;
62+
}
63+
}

0 commit comments

Comments
 (0)