Percolate.php 2.1 KB

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