PHP code example of itrnka / ha-elasticsearch-middleware

1. Go to this page and download the library: Download itrnka/ha-elasticsearch-middleware 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/ */

    

itrnka / ha-elasticsearch-middleware example snippets


$cfg['middleware'] = [

    // ...

    // elasticsearch - single server
    [
        ha\Middleware\NoSQL\Elasticsearch\Elasticsearch::class,
        [
            'name' => 'ES001',
            'hosts' => ['127.0.0.1:9200'],
        ]
    ],

    // elasticsearch - multi server
    [
        ha\Middleware\NoSQL\Elasticsearch\Elasticsearch::class,
        [
            'name' => 'ES002',
            'hosts' => ['10.10.10.1:9200', '10.10.10.2:9200'],
        ]
    ],

    // ...
];

// middleware instance
$es1 = main()->middleware->ES001;
$es2 = main()->middleware->ES002;

// es client (instance of \Elasticsearch\Client):
$es1Client = main()->middleware->ES001->driver();
$es2Client = main()->middleware->ES002->driver();

// or (this is the same)
$es1Client = main()->middleware->ES001->client();
$es2Client = main()->middleware->ES002->client();