Skip to content

Commit

Permalink
Add Indices/Shrink endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
polyfractal committed May 31, 2016
1 parent 3b041f8 commit b6b97a4
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 0 deletions.
101 changes: 101 additions & 0 deletions src/Elasticsearch/Endpoints/Indices/Shrink.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php

namespace Elasticsearch\Endpoints\Indices;

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

/**
* Class Shrink.
*
* @category Elasticsearch
*
* @author Zachary Tong <[email protected]>
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache2
*
* @link http://elastic.co
*/
class Shrink extends AbstractEndpoint
{
// The name of the target index to shrink into
private $target;
/**
* @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;
}

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

return $this;
}

/**
* @throws \Elasticsearch\Common\Exceptions\BadMethodCallException
*
* @return string
*/
protected function getURI()
{
if (isset($this->index) !== true) {
throw new Exceptions\RuntimeException(
'index is required for Shrink'
);
}
if (isset($this->target) !== true) {
throw new Exceptions\RuntimeException(
'target is required for Shrink'
);
}
$index = $this->index;
$target = $this->target;
$uri = "/$index/_shrink/$target";
if (isset($index) === true && isset($target) === true) {
$uri = "/$index/_shrink/$target";
}

return $uri;
}

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

/**
* @return string
*/
protected function getMethod()
{
//TODO Fix Me!
return 'PUT';
}
}
27 changes: 27 additions & 0 deletions src/Elasticsearch/Namespaces/IndicesNamespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,33 @@ public function snapshotIndex($params = array())
return $endpoint->resultOrFuture($response);
}

/**
* $params['index'] = (string) The name of the source index to shrink
* ['target'] = (string) The name of the target index to shrink into
* ['timeout'] = (time) Explicit operation timeout
* ['master_timeout'] = (time) Specify timeout for connection to master
*
* @param $params array Associative array of parameters
*
* @return array
*/
public function shrink($params = array())
{
$index = $this->extractArgument($params, 'index');
$target = $this->extractArgument($params, 'target');

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

/** @var \Elasticsearch\Endpoints\Indices\Shrink $endpoint */
$endpoint = $endpointBuilder('Indices\Shrink');
$endpoint->setIndex($index)
->setTarget($target);
$response = $endpoint->performRequest();

return $endpoint->resultOrFuture($response);
}

/**
* $params['index'] = (list) A comma-separated list of index names; use `_all` or empty string for all indices
* ['type'] = (list) A comma-separated list of document types
Expand Down

0 comments on commit b6b97a4

Please sign in to comment.