Shrink.php 2.0 KB

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