UpdateByQuery.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. namespace Elasticsearch\Endpoints;
  3. use Elasticsearch\Common\Exceptions;
  4. /**
  5. * Class UpdateByQuery
  6. *
  7. * @category Elasticsearch
  8. * @package Elasticsearch\Endpoints *
  9. * @author Zachary Tong <zachary.tong@elasticsearch.com>
  10. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache2
  11. * @link http://elasticsearch.org
  12. */
  13. class UpdateByQuery 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. if (is_array($body) !== true) {
  27. throw new Exceptions\InvalidArgumentException(
  28. 'Body must be an array'
  29. );
  30. }
  31. $this->body = $body;
  32. return $this;
  33. }
  34. /**
  35. * @throws \Elasticsearch\Common\Exceptions\BadMethodCallException
  36. * @return string
  37. */
  38. public function getURI()
  39. {
  40. if (!$this->index) {
  41. throw new Exceptions\RuntimeException(
  42. 'index is required for UpdateByQuery'
  43. );
  44. }
  45. $uri = "/{$this->index}/_update_by_query";
  46. if ($this->type) {
  47. $uri = "/{$this->index}/{$this->type}/_update_by_query";
  48. }
  49. return $uri;
  50. }
  51. /**
  52. * @return string[]
  53. */
  54. public function getParamWhitelist()
  55. {
  56. return [
  57. 'analyzer',
  58. 'analyze_wildcard',
  59. 'default_operator',
  60. 'df',
  61. 'explain',
  62. 'fields',
  63. 'fielddata_fields',
  64. 'from',
  65. 'ignore_unavailable',
  66. 'allow_no_indices',
  67. 'conflicts',
  68. 'expand_wildcards',
  69. 'lenient',
  70. 'lowercase_expanded_terms',
  71. 'preference',
  72. 'q',
  73. 'routing',
  74. 'scroll',
  75. 'search_type',
  76. 'search_timeout',
  77. 'size',
  78. 'sort',
  79. '_source',
  80. '_source_exclude',
  81. '_source_include',
  82. 'terminate_after',
  83. 'stats',
  84. 'suggest_field',
  85. 'suggest_mode',
  86. 'suggest_size',
  87. 'suggest_text',
  88. 'timeout',
  89. 'track_scores',
  90. 'version',
  91. 'version_type',
  92. 'request_cache',
  93. 'refresh',
  94. 'consistency',
  95. 'scroll_size',
  96. 'wait_for_completion',
  97. ];
  98. }
  99. /**
  100. * @return string
  101. */
  102. public function getMethod()
  103. {
  104. return 'POST';
  105. }
  106. }