Elastica\Client::getIndex PHP Method

getIndex() public method

Returns the index for the given connection.
public getIndex ( string $name ) : Index
$name string Index name to create connection to
return Index Index for the given name
    public function getIndex($name)
    {
        return new Index($this, $name);
    }

Usage Example

 /**
  * До любых других действий
  */
 public function initialize()
 {
     $currentActionName = $this->dispatcher->getActiveMethod();
     $annotations = $this->annotations->getMethod(self::class, $currentActionName);
     if ($annotations->has('actionInfo')) {
         $annotation = $annotations->get('actionInfo');
         $actionTitle = $annotation->getNamedArgument('name');
         $this->log->info('Запустили: {actionTitle}', ['actionTitle' => $actionTitle]);
     } else {
         $currentTaskName = $this->dispatcher->getTaskName();
         $this->log->info('Запустили: {currentTaskName}::{currentActionName}', ['currentTaskName' => $currentTaskName, 'currentActionName' => $currentActionName]);
     }
     $this->indexName = $this->dispatcher->getParam('index', 'string', false);
     $this->typeName = $this->dispatcher->getParam('type', 'string', false);
     if (!$this->indexName) {
         $this->log->error('Указание индекса является обязательным параметром');
         die;
     }
     $this->sizePerShard = $this->dispatcher->getParam('sizePerShard', 'int', false) ?: $this->sizePerShard;
     $this->elasticsearchHost = $this->dispatcher->getParam('host', 'string', false) ?: $this->elasticsearchHost;
     $this->elasticsearchPort = $this->dispatcher->getParam('port', 'int', false) ?: $this->elasticsearchPort;
     $connectParams = ['host' => $this->elasticsearchHost, 'port' => $this->elasticsearchPort];
     $this->client = new Client($connectParams);
     try {
         $this->client->getStatus();
     } catch (\Elastica\Exception\Connection\HttpException $e) {
         $context = ['host' => $this->elasticsearchHost, 'port' => $this->elasticsearchPort];
         $this->log->error('Подключение к серверу elasticsearch отсутствует: http://{host}:{port}', $context);
         die;
     }
     $this->elasticaIndex = $this->client->getIndex($this->indexName);
     $this->elasticaType = $this->elasticaIndex->getType($this->typeName);
 }
All Usage Examples Of Elastica\Client::getIndex