|
6 | 6 | use Elastic\Elasticsearch\ClientBuilder; |
7 | 7 | use Ensi\LaravelElasticQuery\Debug\QueryLog; |
8 | 8 | use Ensi\LaravelElasticQuery\Debug\QueryLogRecord; |
| 9 | +use Illuminate\Support\Arr; |
9 | 10 | use Illuminate\Support\Collection; |
10 | 11 |
|
11 | 12 | class ElasticClient |
@@ -73,15 +74,32 @@ public function documentDelete(string $index, int|string $id): array |
73 | 74 |
|
74 | 75 | public function catIndices(string $indexName, ?array $getFields = null): array |
75 | 76 | { |
76 | | - $params = ['index' => "$indexName*"]; |
77 | | - if ($getFields) { |
78 | | - $params['h'] = $getFields; |
| 77 | + $response = $this->client |
| 78 | + ->indices() |
| 79 | + ->stats(['index' => "$indexName*"]) |
| 80 | + ->asArray(); |
| 81 | + |
| 82 | + $results = []; |
| 83 | + foreach ($response['indices'] as $indexName => $stat) { |
| 84 | + $item = [ |
| 85 | + 'index' => $indexName, |
| 86 | + 'health' => $stat['health'], |
| 87 | + 'status' => $stat['status'], |
| 88 | + 'uuid' => $stat['uuid'], |
| 89 | + 'pri' => Arr::get($stat, 'primaries.shard_stats.total_count'), |
| 90 | + 'rep' => Arr::get($stat, 'total.shard_stats.total_count'), |
| 91 | + 'docs.count' => Arr::get($stat, 'total.docs.count'), |
| 92 | + 'docs.deleted' => Arr::get($stat, 'total.docs.deleted'), |
| 93 | + 'store.size' => Arr::get($stat, 'total.store.size_in_bytes'), |
| 94 | + 'pri.store.size' => Arr::get($stat, 'primaries.store.size_in_bytes'), |
| 95 | + ]; |
| 96 | + |
| 97 | + $results[] = !$getFields |
| 98 | + ? $item |
| 99 | + : Arr::only($item, $getFields); |
79 | 100 | } |
80 | 101 |
|
81 | | - return $this->client |
82 | | - ->cat() |
83 | | - ->indices($params) |
84 | | - ->asArray(); |
| 102 | + return $results; |
85 | 103 | } |
86 | 104 |
|
87 | 105 | public function indicesDelete(string $indexName): array |
|
0 commit comments