1<?php
2
3declare(strict_types = 1);
4
5namespace Elasticsearch\Endpoints\Indices;
6
7use Elasticsearch\Endpoints\AbstractEndpoint;
8
9/**
10 * Class Stats
11 *
12 * @category Elasticsearch
13 * @package  Elasticsearch\Endpoints\Indices
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 Stats extends AbstractEndpoint
19{
20    /**
21     * Limit the information returned the specific metrics.
22     *
23     * @var string
24     */
25    private $metric;
26
27    /**
28     * @param string|string[] $metric
29     */
30    public function setMetric($metric): Stats
31    {
32        if (isset($metric) !== true) {
33            return $this;
34        }
35
36        if (is_array($metric)) {
37            $metric = implode(",", $metric);
38        }
39
40        $this->metric = $metric;
41
42        return $this;
43    }
44
45    public function getURI(): string
46    {
47        $index = $this->index ?? null;
48        $metric = $this->metric ?? null;
49
50        if (isset($index) && isset($metric)) {
51            return "/$index/_stats/$metric";
52        }
53        if (isset($index)) {
54            return "/$index/_stats";
55        }
56        if (isset($metric)) {
57            return "/_stats/$metric";
58        }
59        return "/_stats";
60    }
61
62    public function getParamWhitelist(): array
63    {
64        return [
65            'completion_fields',
66            'fielddata_fields',
67            'fields',
68            'groups',
69            'level',
70            'types',
71            'include_segment_file_sizes'
72        ];
73    }
74
75    public function getMethod(): string
76    {
77        return 'GET';
78    }
79}
80