Skip to content

Commit

Permalink
Add Indices/Split endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
polyfractal committed Jan 7, 2019
1 parent 00800c1 commit 46d5a7a
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 0 deletions.
98 changes: 98 additions & 0 deletions src/Elasticsearch/Endpoints/Indices/Split.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php

declare(strict_types = 1);

namespace Elasticsearch\Endpoints\Indices;

use Elasticsearch\Endpoints\AbstractEndpoint;
use Elasticsearch\Common\Exceptions;

/**
* Class Split
*
* @category Elasticsearch
* @package Elasticsearch\Endpoints\Indices
* @author Zachary Tong <[email protected]>
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache2
* @link http://elastic.co
*/
class Split extends AbstractEndpoint
{

private $target;

/**
* @param array|object $body
*
* @return $this
*/
public function setBody($body)
{
if (isset($body) !== true) {
return $this;
}

$this->body = $body;

return $this;
}

/**
* @param string $target
*
* @return $this
*/
public function setTarget($target)
{
if ($target === null) {
return $this;
}
$this->target = $target;

return $this;
}

/**
* @throws \Elasticsearch\Common\Exceptions\RuntimeException
* @return string
*/
public function getURI()
{
if (isset($this->index) !== true) {
throw new Exceptions\RuntimeException(
'index is required for Split'
);
}

if (isset($this->target) !== true) {
throw new Exceptions\RuntimeException(
'target is required for Split'
);
}

$uri = "/{$this->index}/_split/{$this->target}";

return $uri;
}

/**
* @return string[]
*/
public function getParamWhitelist()
{
return array(
'copy_settings',
'timeout',
'master_timeout',
'wait_for_active_shards'
);
}

/**
* @return string
*/
public function getMethod()
{
return 'PUT';
}
}
32 changes: 32 additions & 0 deletions src/Elasticsearch/Namespaces/IndicesNamespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -1162,4 +1162,36 @@ public function rollover($params)

return $this->performRequest($endpoint);
}

/**
* $params['index'] = (string) The name of the source index to split
* ['target'] = (string) The name of the target index to split into
* ['copy_settings'] = (boolean) whether or not to copy settings from the source index (defaults to false)
* ['timeout'] = (time) Explicit operation timeout
* ['master_timeout'] = (time) Specify timeout for connection to master
* ['wait_for_active_shards'] = (string) Set the number of active shards to wait for on the shrunken index before the operation returns.
*
* @param array $params Associative array of parameters
*
* @return array
* @throws \Exception
*/
public function split($params = array())
{
$index = $this->extractArgument($params, 'index');
$body = $this->extractArgument($params, 'body');
$target = $this->extractArgument($params, 'target');

/** @var callback $endpointBuilder */
$endpointBuilder = $this->endpoints;

/** @var \Elasticsearch\Endpoints\Indices\Split $endpoint */
$endpoint = $endpointBuilder('Indices\Split');
$endpoint->setIndex($index)
->setBody($body)
->setTarget($target);
$endpoint->setParams($params);

return $this->performRequest($endpoint);
}
}

0 comments on commit 46d5a7a

Please sign in to comment.