Skip to content

Commit 1ba8299

Browse files
committed
Add Indices/Rollover endpoint
1 parent 6a315e0 commit 1ba8299

File tree

2 files changed

+138
-0
lines changed

2 files changed

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

src/Elasticsearch/Namespaces/IndicesNamespace.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,4 +1166,34 @@ public function shardStores($params)
11661166

11671167
return $endpoint->resultOrFuture($response);
11681168
}
1169+
1170+
/**
1171+
* $params['newIndex'] = (string) The name of the rollover index
1172+
* ['alias'] = (string) The name of the alias to rollover
1173+
* ['timeout'] = (time) Explicit operation timeout
1174+
* ['master_timeout'] = (time) Specify timeout for connection to master
1175+
*
1176+
* @param $params array Associative array of parameters
1177+
*
1178+
* @return array
1179+
*/
1180+
public function rollover($params)
1181+
{
1182+
$newIndex = $this->extractArgument($params, 'newIndex');
1183+
$alias = $this->extractArgument($params, 'alias');
1184+
$body = $this->extractArgument($params, 'body');
1185+
1186+
/** @var callback $endpointBuilder */
1187+
$endpointBuilder = $this->endpoints;
1188+
1189+
/** @var \Elasticsearch\Endpoints\Indices\Rollover $endpoint */
1190+
$endpoint = $endpointBuilder('Indices\Rollover');
1191+
$endpoint->setNewIndex($newIndex)
1192+
->setAlias($alias)
1193+
->setParams($params)
1194+
->setBody($body);
1195+
$response = $endpoint->performRequest();
1196+
1197+
return $endpoint->resultOrFuture($response);
1198+
}
11691199
}

0 commit comments

Comments
 (0)