Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FOSElasticaBundle for Symfony2. How to configure to connect to a cluster?

I'm using Elasticsearch and Symfony2 in a system via FOSElasticaBundle.

While I was using only one server it was ok to configure the clients config like this: https://github.com/FriendsOfSymfony/FOSElasticaBundle#basic-configuration

fos_elastica:
    clients:
        default: { host: localhost, port: 9200 }

But when it comes to a cluster, I've tried to configure in some ways but it does not work, like this:

fos_elastica:
    clients:
        default: [{host: localhost, port: 9200},{host: localhost, port: 9201}]

And this:

fos_elastica:
    clients:
        default:
            - { host: localhost, port: 9200 }
            - { host: localhost, port: 9201 }

I know that FOSElasticaBundle uses the Elastica library, and that library connects to clusters using arrays of parameters, that is why I have tried those approaches above.

Does anyone know how to connect to configure FOSElasticaBundle to connect to some cluster?

Thanks in advance.

like image 953
Mestre San Avatar asked Oct 01 '22 11:10

Mestre San


1 Answers

you don't really need to list all your nodes, as ElasticSearch does load balance the cluster. However, it's still possible to do (e.g. in case the node you connect to goes offline). Keep in mind that it's just simple round robin though.

This is how you do it:

fos_elastica:
    clients:
        default:
            servers: 
                - { host: localhost, port: 9200 }
                - { host: localhost, port: 9201 }
like image 175
r1pp3rj4ck Avatar answered Oct 17 '22 23:10

r1pp3rj4ck