forked from ruflin/Elastica
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStats.php
More file actions
107 lines (94 loc) · 2.04 KB
/
Stats.php
File metadata and controls
107 lines (94 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
namespace Elastica\Index;
use Elastica\Index;
use Elastica\Response;
/**
* Elastica index stats object.
*
* @author Nicolas Ruflin <spam@ruflin.com>
*
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-stats.html
*/
class Stats
{
/**
* Response.
*
* @var Response Response object
*/
protected $_response;
/**
* Stats info.
*
* @var array Stats info
*/
protected $_data = [];
/**
* Index.
*
* @var Index
*/
protected $_index;
/**
* Construct.
*/
public function __construct(Index $index)
{
$this->_index = $index;
$this->refresh();
}
/**
* Returns the raw stats info.
*
* @return array Stats info
*/
public function getData(): array
{
return $this->_data;
}
/**
* Returns the entry in the data array based on the params.
* Various params possible.
*
* @return mixed Data array entry or null if not found
*/
public function get(...$args)
{
$data = $this->getData();
foreach ($args as $arg) {
if (isset($data[$arg])) {
$data = $data[$arg];
} else {
return null;
}
}
return $data;
}
/**
* Returns the index object.
*/
public function getIndex(): Index
{
return $this->_index;
}
/**
* Returns response object.
*
* @return Response Response object
*/
public function getResponse(): Response
{
return $this->_response;
}
/**
* Reloads all status data of this object.
*/
public function refresh(): void
{
$esResponse = $this->getIndex()->getClient()->getConnection()->getClient()->indices()->stats([
'index' => $this->getIndex()->getName(),
]);
$this->_response = new Response($esResponse->asArray(), $esResponse->getStatusCode());
$this->_data = $this->getResponse()->getData();
}
}