Stats.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace Elasticsearch\Endpoints\Indices;
  3. use Elasticsearch\Endpoints\AbstractEndpoint;
  4. /**
  5. * Class Stats
  6. *
  7. * @category Elasticsearch
  8. * @package Elasticsearch\Endpoints\Indices
  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 Stats extends AbstractEndpoint
  14. {
  15. // Limit the information returned the specific metrics.
  16. private $metric;
  17. /**
  18. * @param $metric
  19. *
  20. * @return $this
  21. */
  22. public function setMetric($metric)
  23. {
  24. if (isset($metric) !== true) {
  25. return $this;
  26. }
  27. if (is_array($metric)) {
  28. $metric = implode(",", $metric);
  29. }
  30. $this->metric = $metric;
  31. return $this;
  32. }
  33. /**
  34. * @return string
  35. */
  36. public function getURI()
  37. {
  38. $index = $this->index;
  39. $metric = $this->metric;
  40. $uri = "/_stats";
  41. if (isset($index) === true && isset($metric) === true) {
  42. $uri = "/$index/_stats/$metric";
  43. } elseif (isset($index) === true) {
  44. $uri = "/$index/_stats";
  45. } elseif (isset($metric) === true) {
  46. $uri = "/_stats/$metric";
  47. }
  48. return $uri;
  49. }
  50. /**
  51. * @return string[]
  52. */
  53. public function getParamWhitelist()
  54. {
  55. return array(
  56. 'completion_fields',
  57. 'fielddata_fields',
  58. 'fields',
  59. 'groups',
  60. 'human',
  61. 'level',
  62. 'types',
  63. 'metric',
  64. 'include_segment_file_sizes'
  65. );
  66. }
  67. /**
  68. * @return string
  69. */
  70. public function getMethod()
  71. {
  72. return 'GET';
  73. }
  74. }