5

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.

Mestre San
  • 1,806
  • 15
  • 24

1 Answers1

4

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 }
r1pp3rj4ck
  • 1,437
  • 2
  • 10
  • 23
  • Thanks r1pp3rj4ck, that is exactly what I need. I'm working on some High Availability environment, that's why I need to pass more than one node of the cluster. I'd like to ask you where did you find that configuration? – Mestre San Mar 03 '14 at 16:50
  • 1
    right here in this patch: https://github.com/FriendsOfSymfony/FOSElasticaBundle/pull/191/files :) I guess I'll send a docs PR :D – r1pp3rj4ck Mar 04 '14 at 13:17