Skip to content

Commit f95186e

Browse files
committed
Add Indices/Split endpoint
1 parent 337b1e2 commit f95186e

File tree

2 files changed

+130
-0
lines changed

2 files changed

+130
-0
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
namespace Elasticsearch\Endpoints\Indices;
6+
7+
use Elasticsearch\Endpoints\AbstractEndpoint;
8+
use Elasticsearch\Common\Exceptions;
9+
10+
/**
11+
* Class Split
12+
*
13+
* @category Elasticsearch
14+
* @package Elasticsearch\Endpoints\Indices
15+
* @author Zachary Tong <[email protected]>
16+
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache2
17+
* @link http://elastic.co
18+
*/
19+
class Split extends AbstractEndpoint
20+
{
21+
22+
private $target;
23+
24+
/**
25+
* @param array|object $body
26+
*
27+
* @return $this
28+
*/
29+
public function setBody($body)
30+
{
31+
if (isset($body) !== true) {
32+
return $this;
33+
}
34+
35+
$this->body = $body;
36+
37+
return $this;
38+
}
39+
40+
/**
41+
* @param string $target
42+
*
43+
* @return $this
44+
*/
45+
public function setTarget($target)
46+
{
47+
if ($target === null) {
48+
return $this;
49+
}
50+
$this->target = $target;
51+
52+
return $this;
53+
}
54+
55+
/**
56+
* @throws \Elasticsearch\Common\Exceptions\RuntimeException
57+
* @return string
58+
*/
59+
public function getURI()
60+
{
61+
if (isset($this->index) !== true) {
62+
throw new Exceptions\RuntimeException(
63+
'index is required for Split'
64+
);
65+
}
66+
67+
if (isset($this->target) !== true) {
68+
throw new Exceptions\RuntimeException(
69+
'target is required for Split'
70+
);
71+
}
72+
73+
$uri = "/{$this->index}/_split/{$this->target}";
74+
75+
return $uri;
76+
}
77+
78+
/**
79+
* @return string[]
80+
*/
81+
public function getParamWhitelist()
82+
{
83+
return array(
84+
'copy_settings',
85+
'timeout',
86+
'master_timeout',
87+
'wait_for_active_shards'
88+
);
89+
}
90+
91+
/**
92+
* @return string
93+
*/
94+
public function getMethod()
95+
{
96+
return 'PUT';
97+
}
98+
}

src/Elasticsearch/Namespaces/IndicesNamespace.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,4 +1164,36 @@ public function rollover($params)
11641164

11651165
return $this->performRequest($endpoint);
11661166
}
1167+
1168+
/**
1169+
* $params['index'] = (string) The name of the source index to split
1170+
* ['target'] = (string) The name of the target index to split into
1171+
* ['copy_settings'] = (boolean) whether or not to copy settings from the source index (defaults to false)
1172+
* ['timeout'] = (time) Explicit operation timeout
1173+
* ['master_timeout'] = (time) Specify timeout for connection to master
1174+
* ['wait_for_active_shards'] = (string) Set the number of active shards to wait for on the shrunken index before the operation returns.
1175+
*
1176+
* @param array $params Associative array of parameters
1177+
*
1178+
* @return array
1179+
* @throws \Exception
1180+
*/
1181+
public function split($params = array())
1182+
{
1183+
$index = $this->extractArgument($params, 'index');
1184+
$body = $this->extractArgument($params, 'body');
1185+
$target = $this->extractArgument($params, 'target');
1186+
1187+
/** @var callback $endpointBuilder */
1188+
$endpointBuilder = $this->endpoints;
1189+
1190+
/** @var \Elasticsearch\Endpoints\Indices\Split $endpoint */
1191+
$endpoint = $endpointBuilder('Indices\Split');
1192+
$endpoint->setIndex($index)
1193+
->setBody($body)
1194+
->setTarget($target);
1195+
$endpoint->setParams($params);
1196+
1197+
return $this->performRequest($endpoint);
1198+
}
11671199
}

0 commit comments

Comments
 (0)