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