src/commands/ElasticIndexController.php
public function actionFillIndex()
    {
        try {
            $this->client->ping();
        } catch (NoNodesAvailableException $e) {
            $this->stderr($e->getMessage() . ', maybe you first need to configure and run elasticsearch' . PHP_EOL);
            return;
        }
        /** @var HasProperties | PropertiesTrait $model */
        foreach ($this->applicables as $indexName => $model) {
            if (true === $this->client->indices()->exists(['index' => $indexName])) {
                $this->client->indices()->delete(['index' => $indexName]);
            }
            $config = self::prepareIndexConfig();
            $config['index'] = $indexName;
            $response = $this->client->indices()->create($config);
            if (true === isset($response['acknowledged']) && $response['acknowledged'] == 1) {
                foreach (self::$storage as $className => $id) {
                    $indexData = self::prepareIndexData($model, $indexName, $className, $id);
                    if (false === empty($indexData['body'])) {
                        $this->client->bulk($indexData);
                    }
                }
            }
        }
    }
public function actionFillIndex()
    {
        try {
            $this->client->ping();
        } catch (NoNodesAvailableException $e) {
            $this->stderr($e->getMessage() . ', maybe you first need to configure and run elasticsearch' . PHP_EOL);
            return;
        }
        /** @var HasProperties | PropertiesTrait $model */
        foreach ($this->applicables as $indexName => $model) {
            if (true === $this->client->indices()->exists(['index' => $indexName])) {
                $this->client->indices()->delete(['index' => $indexName]);
            }
            $config = self::prepareIndexConfig();
            $config['index'] = $indexName;
            $response = $this->client->indices()->create($config);
            if (true === isset($response['acknowledged']) && $response['acknowledged'] == 1) {
                foreach (self::$storage as $className => $id) {
                    $indexData = self::prepareIndexData($model, $indexName, $className, $id);
                    if (false === empty($indexData['body'])) {
                        $this->client->bulk($indexData);
                    }
                }
            }
        }
    }
public function actionFillIndex ( ) { try { $ this -> client -> ping ( ) ; } catch ( NoNodesAvailableException $ e ) { $ this -> stderr ( $ e -> getMessage ( ) . ', maybe you first need to configure and run elasticsearch' . PHP_EOL ) ; return ; } /** @var HasProperties | PropertiesTrait $model */ foreach ( $ this -> applicables as $ indexName => $ model ) { if ( true === $ this -> client -> indices ( ) -> exists ( [ 'index' => $ indexName ] ) ) { $ this -> client -> indices ( ) -> delete ( [ 'index' => $ indexName ] ) ; } $ config = self :: prepareIndexConfig ( ) ; $ config [ 'index' ] = $ indexName ; $ response = $ this -> client -> indices ( ) -> create ( $ config ) ; if ( true === isset ( $ response [ 'acknowledged' ] ) && $ response [ 'acknowledged' ] == 1 ) { foreach ( self :: $ storage as $ className => $ id ) { $ indexData = self :: prepareIndexData ( $ model , $ indexName , $ className , $ id ) ; if ( false === empty ( $ indexData [ 'body' ] ) ) { $ this -> client -> bulk ( $ indexData ) ; } } } } }
Creates and fills in indices

@throws \yii\base\InvalidConfigException
Creates and fills in indices