GetField.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace Elasticsearch\Endpoints\Indices\Mapping;
  3. use Elasticsearch\Endpoints\AbstractEndpoint;
  4. use Elasticsearch\Common\Exceptions;
  5. /**
  6. * Class GetField
  7. *
  8. * @category Elasticsearch
  9. * @package Elasticsearch\Endpoints\Indices\Mapping
  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 GetField extends AbstractEndpoint
  15. {
  16. /** @var string */
  17. private $fields;
  18. /**
  19. * @param string|array $fields
  20. *
  21. * @return $this
  22. */
  23. public function setFields($fields)
  24. {
  25. if (isset($fields) !== true) {
  26. return $this;
  27. }
  28. if (is_array($fields) === true) {
  29. $fields = implode(",", $fields);
  30. }
  31. $this->fields = $fields;
  32. return $this;
  33. }
  34. /**
  35. * @throws \Elasticsearch\Common\Exceptions\RuntimeException
  36. * @return string
  37. */
  38. public function getURI()
  39. {
  40. if (isset($this->fields) !== true) {
  41. throw new Exceptions\RuntimeException(
  42. 'fields is required for Get Field Mapping'
  43. );
  44. }
  45. $uri = $this->getOptionalURI('_mapping/field');
  46. return $uri.'/'.$this->fields;
  47. }
  48. /**
  49. * @return string[]
  50. */
  51. public function getParamWhitelist()
  52. {
  53. return array(
  54. 'include_defaults',
  55. 'ignore_unavailable',
  56. 'allow_no_indices',
  57. 'expand_wildcards',
  58. 'local'
  59. );
  60. }
  61. /**
  62. * @return string
  63. */
  64. public function getMethod()
  65. {
  66. return 'GET';
  67. }
  68. }