node.js elasticsearch multiple hosts

In my node application i have used "Elasticsearch" for data retrieval. When i connecting to only 1 host it works fine.

for ex:

try {
        elasticSearchClient = new ElasticSearchClient({
        host: 'xxx.xxx.x.xxxx',
        port: '9200'
    });
} catch (err) {
    console.log('err=' + err);
}

But when i tried to connect to multiple hosts(instance) i am getting error:

For ex:

var serverOptions = {
    hosts:[

        {
            host: 'xxx.xxx.x.xxx',
            port: 9200
        },{
            host: 'xxx.xxx.x.xxx',
            port: 9200
        }]
};

elasticSearchClient = new ElasticSearchClient(serverOptions);

Error:

ECONN REFUSED: socket hang up

I am using "elsaticsearchclient' node package. Help me to solve this. Thanks in advance..

EDIT:

Actually 1 host is up and another host is down. So when 1 of the host is down i have to redirect to another host.. How can i achieve this??

hosts should be an array of full URLs. So do the following:

elasticSearchClient = elasticsearch.Client({
    hosts: serverOptions.hosts.map(function (server) {
        return 'http://' + serverOptions.user + ':' + serverOptions.password + '@' + server.host + ':' + server.port;
    })
}),