I'm getting following exception while trying to upload document on SolrCloud using CloudSolrServer.
Exception in thread "main" org.apache.solr.common.SolrException: Could not find collection : gettingstarted
at org.apache.solr.common.cloud.ClusterState.getCollection(ClusterState.java:162)
at org.apache.solr.client.solrj.impl.CloudSolrServer.directUpdate(CloudSolrServer.java:305)
at org.apache.solr.client.solrj.impl.CloudSolrServer.request(CloudSolrServer.java:533)
at org.apache.solr.client.solrj.request.AbstractUpdateRequest.process(AbstractUpdateRequest.java:124)
at org.apache.solr.client.solrj.SolrServer.add(SolrServer.java:116)
at org.apache.solr.client.solrj.SolrServer.add(SolrServer.java:102)
at Test.addDocumentSolrCloud(Test.java:265)
at Test.main(Test.java:284)
The collection exists and I can query using Solr admin. And Also able to upload document using HttpSolrServer (single instance - non cloud mode).
I'm using the following code snippet
CloudSolrServer server = new CloudSolrServer("localhost:2181");
server.setDefaultCollection("gettingstarted");
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", id);
doc.addField("name", name);
server.add(doc);
server.commit();
Not sure what I'm missing. My Zookeeper is running externally on same machine where both solr cloud nodes are
I'm able to figure out the problem. In fact the cluster/cloud was configure rightly but SolrJ-4.x can't be used with Solr 5.0.0; particularly the Cloud Solr API; besides cloud the other queries using HttpSolrServer were producing the results.
I switched to SolrJ-5.0.0 and modified the snippet as below:
CloudSolrClient cloudSolrClient = new CloudSolrClient("localhost:2181") ;
cloudSolrClient.setDefaultCollection("gettingstarted");
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", id);
doc.addField("name", name);
cloudSolrClient.add(doc);
cloudSolrClient.commit();
The API's are changed/refactored
Adnan