SearchTemplate.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace Elasticsearch\Endpoints;
  3. use Elasticsearch\Common\Exceptions\InvalidArgumentException;
  4. use Elasticsearch\Common\Exceptions;
  5. /**
  6. * Class SearchTemplate
  7. *
  8. * @category Elasticsearch
  9. * @package Elasticsearch\Endpoints
  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 SearchTemplate 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. * @return string
  32. */
  33. public function getURI()
  34. {
  35. $index = $this->index;
  36. $type = $this->type;
  37. $uri = "/_search/template";
  38. if (isset($index) === true && isset($type) === true) {
  39. $uri = "/$index/$type/_search/template";
  40. } elseif (isset($index) === true) {
  41. $uri = "/$index/_search/template";
  42. } elseif (isset($type) === true) {
  43. $uri = "/_all/$type/_search/template";
  44. }
  45. return $uri;
  46. }
  47. /**
  48. * @return string[]
  49. */
  50. public function getParamWhitelist()
  51. {
  52. return array(
  53. 'ignore_unavailable',
  54. 'allow_no_indices',
  55. 'expand_wildcards',
  56. 'preference',
  57. 'routing',
  58. 'scroll',
  59. 'search_type'
  60. );
  61. }
  62. /**
  63. * @return string
  64. */
  65. public function getMethod()
  66. {
  67. return 'GET';
  68. }
  69. }