From b6b97a453e18ba531634402ed90d8b0451e4a0fa Mon Sep 17 00:00:00 2001 From: Zachary Tong Date: Tue, 31 May 2016 15:27:26 -0400 Subject: [PATCH] Add Indices/Shrink endpoint --- .../Endpoints/Indices/Shrink.php | 101 ++++++++++++++++++ .../Namespaces/IndicesNamespace.php | 27 +++++ 2 files changed, 128 insertions(+) create mode 100644 src/Elasticsearch/Endpoints/Indices/Shrink.php diff --git a/src/Elasticsearch/Endpoints/Indices/Shrink.php b/src/Elasticsearch/Endpoints/Indices/Shrink.php new file mode 100644 index 000000000..9182acbd5 --- /dev/null +++ b/src/Elasticsearch/Endpoints/Indices/Shrink.php @@ -0,0 +1,101 @@ + + * @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'; + } +} diff --git a/src/Elasticsearch/Namespaces/IndicesNamespace.php b/src/Elasticsearch/Namespaces/IndicesNamespace.php index 9822fbfa2..c113e6ded 100644 --- a/src/Elasticsearch/Namespaces/IndicesNamespace.php +++ b/src/Elasticsearch/Namespaces/IndicesNamespace.php @@ -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