1<?php 2 3namespace Elastica\Cluster\Health; 4 5/** 6 * Wraps status information for an index. 7 * 8 * @author Ray Ward <ray.ward@bigcommerce.com> 9 * 10 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-health.html 11 */ 12class Index 13{ 14 /** 15 * @var string the name of the index 16 */ 17 protected $_name; 18 19 /** 20 * @var array the index health data 21 */ 22 protected $_data; 23 24 /** 25 * @param string $name the name of the index 26 * @param array $data the index health data 27 */ 28 public function __construct(string $name, array $data) 29 { 30 $this->_name = $name; 31 $this->_data = $data; 32 } 33 34 /** 35 * Gets the name of the index. 36 */ 37 public function getName(): string 38 { 39 return $this->_name; 40 } 41 42 /** 43 * Gets the status of the index. 44 * 45 * @return string green, yellow or red 46 */ 47 public function getStatus(): string 48 { 49 return $this->_data['status']; 50 } 51 52 /** 53 * Gets the number of nodes in the index. 54 */ 55 public function getNumberOfShards(): int 56 { 57 return $this->_data['number_of_shards']; 58 } 59 60 /** 61 * Gets the number of data nodes in the index. 62 */ 63 public function getNumberOfReplicas(): int 64 { 65 return $this->_data['number_of_replicas']; 66 } 67 68 /** 69 * Gets the number of active primary shards. 70 */ 71 public function getActivePrimaryShards(): int 72 { 73 return $this->_data['active_primary_shards']; 74 } 75 76 /** 77 * Gets the number of active shards. 78 */ 79 public function getActiveShards(): int 80 { 81 return $this->_data['active_shards']; 82 } 83 84 /** 85 * Gets the number of relocating shards. 86 */ 87 public function getRelocatingShards(): int 88 { 89 return $this->_data['relocating_shards']; 90 } 91 92 /** 93 * Gets the number of initializing shards. 94 */ 95 public function getInitializingShards(): int 96 { 97 return $this->_data['initializing_shards']; 98 } 99 100 /** 101 * Gets the number of unassigned shards. 102 */ 103 public function getUnassignedShards(): int 104 { 105 return $this->_data['unassigned_shards']; 106 } 107 108 /** 109 * Gets the health of the shards in this index. 110 * 111 * @return Shard[] 112 */ 113 public function getShards(): array 114 { 115 $shards = []; 116 foreach ($this->_data['shards'] as $shardNumber => $shard) { 117 $shards[] = new Shard($shardNumber, $shard); 118 } 119 120 return $shards; 121 } 122} 123