Rollover.php 2.1 KB

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