PHP code example of mfuns-cn / hyperf-elasticsearch

1. Go to this page and download the library: Download mfuns-cn/hyperf-elasticsearch library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mfuns-cn / hyperf-elasticsearch example snippets


[
    /*
    |--------------------------------------------------------------------------
    | 自定义 Elasticsearch 客户端配置
    |--------------------------------------------------------------------------
    |
    | 详细设置请参阅:
    | http://www.elasticsearch.org/guide/en/elasticsearch/client/php-api/current/_configuration.html
    */

    'client' => [
        'hosts' => [
            'http://localhost:9200',
        ],
        'retries' => 1,
    ],

    /*
    |--------------------------------------------------------------------------
    | 连接池设置
    |--------------------------------------------------------------------------
    */

    'pool' => [
        'enabled' => true,
        'min_connections' => 1,
        'max_connections' => 30,
        'wait_timeout' => 3.0,
        'max_idle_time' => 60.0,
    ],

    /*
    |--------------------------------------------------------------------------
    | Elasticsearch 日志设置
    |--------------------------------------------------------------------------
    |
    | 启用日志需安装 `hyperf/logger` 组件。
    */

    'logger' => [
        'enabled' => false,
        'name' => 'elasticsearch',
        'group' => 'default',
    ],
];



use Elasticsearch\Client;
use Hyperf\Utils\ApplicationContext;

$client = ApplicationContext::getContainer()->get(Client::class);

$info = $client->info();
shell script
php bin/hyperf.php vendor:publish mfuns-cn/elasticsearch