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