Reply
Explorer
Posts: 16
Registered: ‎01-09-2015

"No live SolrServers available to handle this request" exception when trying to use SolrJ

Hello,

 

I'm using a CDH 5.3.0 cluster, and having problems when trying to use SolrJ (version 4.4.0-cdh5.3.0) to insert a document into Solr. According to the documentation, I can use code like the following to interact with ZooKeeper controlled SolrCloud server:

 

import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.CloudSolrServer;
import org.apache.solr.common.SolrInputDocument;

import java.io.IOException;

public class standaloneCloud {

    public static void main(String [] args) throws IOException, SolrServerException {

            String myId = "myID";
            String myUri = "this is for sure something usefull and stuff!";
            String myLangCode = "ru";
            String myType = "my_type!";


            String zkHostString = "localhost:2181/solr"; // SSH tunnelled to ZooKeeper

            CloudSolrServer server = new CloudSolrServer(zkHostString);
            server.setDefaultCollection("collection3");
            SolrInputDocument doc = new SolrInputDocument();

            doc.addField("id", myId + "___" + "some keyword" );
            doc.addField("uri", myUri );
            doc.addField("alias", "some keyword" );
            doc.addField("langCode", myLangCode );
            doc.addField("type", myType);

            server.add(doc);
            server.commit();
    }
}


 

But when I run it, it gives the following exception:

 

Exception in thread "main" org.apache.solr.client.solrj.SolrServerException: No live SolrServers available to handle this request
	at org.apache.solr.client.solrj.impl.LBHttpSolrServer.request(LBHttpSolrServer.java:289)
	at org.apache.solr.client.solrj.impl.CloudSolrServer.request(CloudSolrServer.java:310)
	at org.apache.solr.client.solrj.request.AbstractUpdateRequest.process(AbstractUpdateRequest.java:117)
	at org.apache.solr.client.solrj.SolrServer.add(SolrServer.java:116)
	at org.apache.solr.client.solrj.SolrServer.add(SolrServer.java:102)
	at standaloneCloud.main(standaloneCloud.java:31)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)

 

I don't understand why it complains about no live Solr servers, because there are live Solr servers, there's a ZooKeeper at the given host:port, and I also checked that it returns the address of a valid Solr server on the cluster.

 

To prove it, on the same cluster, I compile and run the following code that is very similar, only difference being the use of HttpSolrServer directly, instead of CloudSolrServer:

 

import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.common.SolrInputDocument;

public class standalone {
    public static void main(String [] args) {
        try {

            String myId = "myID";
            String myUri = "this is for sure something usefull and stuff!";
            String myLangCode = "ru";
            String myType = "my_type!";

            String solrString ="http://node04.demo.hadoop:8983/solr/collection3";

            HttpSolrServer server = new HttpSolrServer(solrString);

            SolrInputDocument doc = new SolrInputDocument();

            doc.addField("id", myId + "___" + "some keyword" );
            doc.addField("uri", myUri );
            doc.addField("alias", "some keyword" );
            doc.addField("langCode", myLangCode );
            doc.addField("type", myType );

            server.add(doc);
            server.commit();

        } catch (Exception e) {
            System.out.println(e);
        }
    }
}

 

The code above works perfectly fine and inserts the document to Solr to be indexed without any exceptions.

 

So, why can't I use CloudSolrServer and send my document via ZooKeeper when I'm using SolrJ?

 

 

Explorer
Posts: 16
Registered: ‎01-09-2015

Re: "No live SolrServers available to handle this request" exception when trying to use So

We have just upgraded our cluster to the latest version of CDH, now it is CDH 5.3.2 and we're using SolrJ version 4.4.0-cdh5.3.2 like:

 

<dependency>
  <groupId>org.apache.solr</groupId>
  <artifactId>solr-solrj</artifactId>
  <version>4.4.0-cdh5.3.2</version>
</dependency>

And the same Java code as above, and we still get

 

 No live SolrServers available to handle this request

exception.

 

What should we do to send a document to Cloud Solr server via ZooKeeper?

 

 

BAR
New Contributor
Posts: 1
Registered: ‎12-31-2015

Re: "No live SolrServers available to handle this request" exception when trying to use So

Did you ever get an answer for this?  It does the same under 5.5.1 with SolrJ cdh5.2.3

Contributor
Posts: 55
Registered: ‎02-09-2015

Re: "No live SolrServers available to handle this request" exception when trying to use So

i see no need to contact zookeeper at all , all you need is to contact solr directly , i have the below code working fine , try it 

 

import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrInputDocument;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class update_records {


/**
* @param args
* @throws IOException
* @throws SolrServerException
*/

public static void main(String[] args) throws SolrServerException, IOException {
// TODO Auto-generated method stub
HttpSolrServer server = new HttpSolrServer("http://localhost:8983/solr/xml_unstructured");
SolrInputDocument doc = new SolrInputDocument();
Map<String, String> partialUpdate = new HashMap<String, String>();
partialUpdate.put("set", "New title");
doc = new SolrInputDocument();
doc.addField("id", "12331131");
doc.addField("link", "new link");
doc.addField("title", partialUpdate);
server.add(doc);
server.commit();

}

}

Highlighted
Cloudera Employee
Posts: 199
Registered: ‎01-09-2014

Re: "No live SolrServers available to handle this request" exception when trying to use So

Using the CloudSolrServer instead of HttpSolrServer will allow the solrj client to load balance between the available solr servers, and is recommended in a Cloudera Search environment.  The "No live SolrServers available to handle this request" is indicating a problem with the collection you are trying to update.

 

I would suggest reviewing the currently online replicas, via http://solr.server:8983/#/~cloud and you should be able to see if all the replicas for your collection are online.  You need at least one replica per shard to be the leader (as updates go to leaders and then get distributed to associated replicas).

 

-PD

Announcements