1<?php
2
3declare(strict_types = 1);
4
5namespace Elasticsearch\Endpoints;
6
7use Elasticsearch\Common\Exceptions\InvalidArgumentException;
8use Elasticsearch\Common\Exceptions;
9
10/**
11 * Class SearchTemplate
12 *
13 * @category Elasticsearch
14 * @package  Elasticsearch\Endpoints
15 * @author   Zachary Tong <zach@elastic.co>
16 * @license  http://www.apache.org/licenses/LICENSE-2.0 Apache2
17 * @link     http://elastic.co
18 */
19class SearchTemplate extends AbstractEndpoint
20{
21    public function setBody($body): SearchTemplate
22    {
23        if (isset($body) !== true) {
24            return $this;
25        }
26
27        $this->body = $body;
28
29        return $this;
30    }
31
32    public function getURI(): string
33    {
34        $index = $this->index ?? null;
35        $type = $this->type ?? null;
36
37        if (isset($index) && isset($type)) {
38            return "/$index/$type/_search/template";
39        }
40        if (isset($index)) {
41            return "/$index/_search/template";
42        }
43        return "/_search/template";
44    }
45
46    public function getParamWhitelist(): array
47    {
48        return [
49            'ignore_unavailable',
50            'ignore_throttled',
51            'allow_no_indices',
52            'expand_wildcards',
53            'preference',
54            'routing',
55            'scroll',
56            'search_type',
57            'explain',
58            'profile',
59            'typed_keys',
60            'rest_total_hits_as_int',
61            'ccs_minimize_roundtrips'
62        ];
63    }
64
65    public function getMethod(): string
66    {
67        return 'POST';
68    }
69}
70