jolicode / elastically

🔍 JoliCode's Elastica wrapper to bootstrap Elasticsearch PHP integrations
248 stars 37 forks source link

Elastically cluster configuration #104

Closed issam-chouchane closed 2 years ago

issam-chouchane commented 2 years ago

In .Net libraries we can set a cluster config in the Elastic client part by specifying the master and slaves. Can we do the same with Elasticaly, if yes could you provide an exemple of the de Yaml please ?

Thnx.

lyrixx commented 2 years ago

Do you have a link to the .Net lib documentation?

issam-chouchane commented 2 years ago

You can check the library proposed by Elasticsearch :

image

damienalexandre commented 2 years ago

Elastically rely on Elastica, you can have a look here:

https://github.com/ruflin/Elastica/blob/a97ede932024d26bdca8bb05eb3abe3c7942ddbc/src/Client.php#L615-L664

So something like this should work:

// Factory object with Elastica options + new Elastically options in the same array
$factory = new Factory([
    // Where to find the mappings
    Factory::CONFIG_MAPPINGS_DIRECTORY => __DIR__.'/mappings',
    // What object to find in each index
    Factory::CONFIG_INDEX_CLASS_MAPPING => [
        'beers' => Beer::class,
    ],
    'connections' => [
            ['host' => 'server1', 'port' => 9200],
            ['host' =>  'server2', 'port' => 9200],
    ]
]);

// Class to perform request, same as the Elastica Client
$client = $factory->buildClient();

Feel free to reopen this issue if you have any issue with the behavior of Elastically!

issam-chouchane commented 2 years ago

thank you for the exemple. Is there a yaml equivalent implementation ?

damienalexandre commented 2 years ago

Yeaahh.


JoliCode\Elastically\Client:
    arguments:
        $config:
            connections:
              - { host: server1, port: 9200 }
              - { host: server2, port: 9200 }

This issue tracker is not for support, only for bug report by the way.

issam-chouchane commented 2 years ago

that rocks. I ll let you know.