PHP code example of happyr / elastica-dsn

1. Go to this page and download the library: Download happyr/elastica-dsn 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/ */

    

happyr / elastica-dsn example snippets


use Happyr\ElasticaDsn\ClientFactory;

$client = ClientFactory::create('elasticsearch://localhost');
$client = ClientFactory::create('elasticsearch:?host[localhost]&host[localhost:9201]&host[127.0.0.1:9202]');
$client = ClientFactory::create('elasticsearch://foo:bar@localhost:1234');
$client = ClientFactory::create('elasticsearch://localhost:9201', ['username' => 'foo', 'password' => 'bar']);

use Elastica\Client;
use Happyr\ElasticaDsn\ClientFactory;

$config = ClientFactory::getConfig('elasticsearch://localhost');

// Add more stuff to $config array
$client = new Client($config);