Put.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace Elasticsearch\Endpoints\Indices\Mapping;
  3. use Elasticsearch\Endpoints\AbstractEndpoint;
  4. use Elasticsearch\Common\Exceptions;
  5. /**
  6. * Class Put
  7. *
  8. * @category Elasticsearch
  9. * @package Elasticsearch\Endpoints\Indices\Mapping
  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 Put extends AbstractEndpoint
  15. {
  16. /**
  17. * @param array $body
  18. *
  19. * @throws \Elasticsearch\Common\Exceptions\InvalidArgumentException
  20. * @return $this
  21. */
  22. public function setBody($body)
  23. {
  24. if (isset($body) !== true) {
  25. return $this;
  26. }
  27. $this->body = $body;
  28. return $this;
  29. }
  30. /**
  31. * @throws \Elasticsearch\Common\Exceptions\RuntimeException
  32. * @return string
  33. */
  34. public function getURI()
  35. {
  36. if (isset($this->type) !== true) {
  37. throw new Exceptions\RuntimeException(
  38. 'type is required for Put'
  39. );
  40. }
  41. $index = $this->index;
  42. $type = $this->type;
  43. $uri = "/_mapping/$type";
  44. if (isset($index) === true && isset($type) === true) {
  45. $uri = "/$index/$type/_mapping";
  46. } elseif (isset($type) === true) {
  47. $uri = "/_mapping/$type";
  48. }
  49. return $uri;
  50. }
  51. /**
  52. * @return string[]
  53. */
  54. public function getParamWhitelist()
  55. {
  56. return array(
  57. 'ignore_conflicts',
  58. 'timeout',
  59. 'master_timeout',
  60. 'ignore_unavailable',
  61. 'allow_no_indices',
  62. 'expand_wildcards',
  63. 'update_all_types'
  64. );
  65. }
  66. /**
  67. * @return array
  68. * @throws \Elasticsearch\Common\Exceptions\RuntimeException
  69. */
  70. public function getBody()
  71. {
  72. if (isset($this->body) !== true) {
  73. throw new Exceptions\RuntimeException('Body is required for Put Mapping');
  74. }
  75. return $this->body;
  76. }
  77. /**
  78. * @return string
  79. */
  80. public function getMethod()
  81. {
  82. return 'PUT';
  83. }
  84. }