Explain.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace Elasticsearch\Endpoints;
  3. use Elasticsearch\Common\Exceptions;
  4. /**
  5. * Class Explain
  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 Explain 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->id) !== true) {
  36. throw new Exceptions\RuntimeException(
  37. 'id is required for Explain'
  38. );
  39. }
  40. if (isset($this->index) !== true) {
  41. throw new Exceptions\RuntimeException(
  42. 'index is required for Explain'
  43. );
  44. }
  45. if (isset($this->type) !== true) {
  46. throw new Exceptions\RuntimeException(
  47. 'type is required for Explain'
  48. );
  49. }
  50. $id = $this->id;
  51. $index = $this->index;
  52. $type = $this->type;
  53. $uri = "/$index/$type/$id/_explain";
  54. if (isset($index) === true && isset($type) === true && isset($id) === true) {
  55. $uri = "/$index/$type/$id/_explain";
  56. }
  57. return $uri;
  58. }
  59. /**
  60. * @return string[]
  61. */
  62. public function getParamWhitelist()
  63. {
  64. return array(
  65. 'analyze_wildcard',
  66. 'analyzer',
  67. 'default_operator',
  68. 'df',
  69. 'fields',
  70. 'lenient',
  71. 'lowercase_expanded_terms',
  72. 'parent',
  73. 'preference',
  74. 'q',
  75. 'routing',
  76. 'source',
  77. '_source',
  78. '_source_exclude',
  79. '_source_include',
  80. 'stored_fields'
  81. );
  82. }
  83. /**
  84. * @return string
  85. */
  86. public function getMethod()
  87. {
  88. return 'GET';
  89. }
  90. }