Search code examples
solrapache-zookeepersolrcloud

How to make a request in SolrCloud?


I have a Node.js app and I used to have a standalone Solr but then our company decided to use SolrCloud to provide failover.

In the standalone Solr I had only the one server with it and I had all my requests like: http://solr_server:8983/solr/mycore/select?indent=on&q=*:*&wt=json so all requests led to the same server all the time.

But now I have 3 different instances with 1 ZooKeeper and 1 Solr node on each of them and my requests look like this: http://solr_server_1:8983/solr/mycollection/select?q=*:*
And now the question: what if the solr_server_1 will go down? How can I still get my results? How can I handle requests in this case?


Solution

  • If you're doing this manually: You'll have to catch the exception when the connection fails, and then retry the next server in your list.

    let servers = ['ip1:8983', 'ip2:8983', 'ip3:8983']
    

    If you're using a library that supports Zookeeper (i.e. it connects to zookeeper to find out what the live nodes are), you give the client a list of zookeeper nodes and lets it figure out the rest. node-solr-smart-client is a client that supports Zookeeper as well.

    options = {
        zkConnectionString: 'ip1:2181,ip2:2181,ip3:2181',
        // etc.
    }
    
    solrSmartClient.createClient('my_solr_collection', options, function (err, solrClient) {