Skip to content

Commit b6b97a4

Browse files
committed
Add Indices/Shrink endpoint
1 parent 3b041f8 commit b6b97a4

File tree

2 files changed

+128
-0
lines changed

2 files changed

+128
-0
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
3+
namespace Elasticsearch\Endpoints\Indices;
4+
5+
use Elasticsearch\Endpoints\AbstractEndpoint;
6+
use Elasticsearch\Common\Exceptions;
7+
8+
/**
9+
* Class Shrink.
10+
*
11+
* @category Elasticsearch
12+
*
13+
* @author Zachary Tong <zach@elastic.co>
14+
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache2
15+
*
16+
* @link http://elastic.co
17+
*/
18+
class Shrink extends AbstractEndpoint
19+
{
20+
// The name of the target index to shrink into
21+
private $target;
22+
/**
23+
* @param array $body
24+
*
25+
* @throws \Elasticsearch\Common\Exceptions\InvalidArgumentException
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 $target
42+
*
43+
* @return $this
44+
*/
45+
public function setTarget($target)
46+
{
47+
if (isset($target) !== true) {
48+
return $this;
49+
}
50+
$this->target = $target;
51+
52+
return $this;
53+
}
54+
55+
/**
56+
* @throws \Elasticsearch\Common\Exceptions\BadMethodCallException
57+
*
58+
* @return string
59+
*/
60+
protected function getURI()
61+
{
62+
if (isset($this->index) !== true) {
63+
throw new Exceptions\RuntimeException(
64+
'index is required for Shrink'
65+
);
66+
}
67+
if (isset($this->target) !== true) {
68+
throw new Exceptions\RuntimeException(
69+
'target is required for Shrink'
70+
);
71+
}
72+
$index = $this->index;
73+
$target = $this->target;
74+
$uri = "/$index/_shrink/$target";
75+
if (isset($index) === true && isset($target) === true) {
76+
$uri = "/$index/_shrink/$target";
77+
}
78+
79+
return $uri;
80+
}
81+
82+
/**
83+
* @return string[]
84+
*/
85+
protected function getParamWhitelist()
86+
{
87+
return array(
88+
'timeout',
89+
'master_timeout',
90+
);
91+
}
92+
93+
/**
94+
* @return string
95+
*/
96+
protected function getMethod()
97+
{
98+
//TODO Fix Me!
99+
return 'PUT';
100+
}
101+
}

src/Elasticsearch/Namespaces/IndicesNamespace.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,33 @@ public function snapshotIndex($params = array())
242242
return $endpoint->resultOrFuture($response);
243243
}
244244

245+
/**
246+
* $params['index'] = (string) The name of the source index to shrink
247+
* ['target'] = (string) The name of the target index to shrink into
248+
* ['timeout'] = (time) Explicit operation timeout
249+
* ['master_timeout'] = (time) Specify timeout for connection to master
250+
*
251+
* @param $params array Associative array of parameters
252+
*
253+
* @return array
254+
*/
255+
public function shrink($params = array())
256+
{
257+
$index = $this->extractArgument($params, 'index');
258+
$target = $this->extractArgument($params, 'target');
259+
260+
/** @var callback $endpointBuilder */
261+
$endpointBuilder = $this->endpoints;
262+
263+
/** @var \Elasticsearch\Endpoints\Indices\Shrink $endpoint */
264+
$endpoint = $endpointBuilder('Indices\Shrink');
265+
$endpoint->setIndex($index)
266+
->setTarget($target);
267+
$response = $endpoint->performRequest();
268+
269+
return $endpoint->resultOrFuture($response);
270+
}
271+
245272
/**
246273
* $params['index'] = (list) A comma-separated list of index names; use `_all` or empty string for all indices
247274
* ['type'] = (list) A comma-separated list of document types

0 commit comments

Comments
 (0)