Mget.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace Elasticsearch\Endpoints;
  3. use Elasticsearch\Common\Exceptions;
  4. /**
  5. * Class Mget
  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 Mget 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. * @return string
  31. */
  32. public function getURI()
  33. {
  34. $index = $this->index;
  35. $type = $this->type;
  36. $uri = "/_mget";
  37. if (isset($index) === true && isset($type) === true) {
  38. $uri = "/$index/$type/_mget";
  39. } elseif (isset($index) === true) {
  40. $uri = "/$index/_mget";
  41. } elseif (isset($type) === true) {
  42. $uri = "/_all/$type/_mget";
  43. }
  44. return $uri;
  45. }
  46. /**
  47. * @return string[]
  48. */
  49. public function getParamWhitelist()
  50. {
  51. return array(
  52. 'fields',
  53. 'preference',
  54. 'realtime',
  55. 'refresh',
  56. '_source',
  57. '_source_exclude',
  58. '_source_include',
  59. 'routing',
  60. 'stored_fields'
  61. );
  62. }
  63. /**
  64. * @return array
  65. * @throws \Elasticsearch\Common\Exceptions\RuntimeException
  66. */
  67. public function getBody()
  68. {
  69. if (isset($this->body) !== true) {
  70. throw new Exceptions\RuntimeException('Body is required for MGet');
  71. }
  72. return $this->body;
  73. }
  74. /**
  75. * @return string
  76. */
  77. public function getMethod()
  78. {
  79. return 'POST';
  80. }
  81. }