Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to query using CloudSorlServer

Tags:

java

solr

bigdata

I have a problem when I want to query from my java web service into solr server. My code looks like this:

CloudSolrServer solr = new CloudSolrServer("BigDataNew1:2181,BigDataNew2:2181,BigDataNew3:2181,BigDataNew4:2181,BigDataNew5:2181/solr");
Solr Queryquery = new SolrQuery();
ModifiableSolrParams param = new ModifiableSolrParams();
param.set("q",keyword).set("fl"," id, title, desc, pubDate, media, person, location").set("count","1").set("wt", "json").set("facet", true).set("start", "0").set("rows", "5");
QueryResponse response = solr.query(param);
SolrDocumentList list = response.getResults();

I got the following error:org.apache.solr.client.solrj.SolrServerException: No collection param specified on request and no default collection has been set.

Anybody know what the problem is?

Thanks

like image 408
Aditia Rakhmat Avatar asked Dec 02 '25 09:12

Aditia Rakhmat


1 Answers

You'll need to tell CloudSolrServer which collection you want to query.

You can do this by setting it with setDefaultCollection:

solr.setDefaultCollection("foobar");
like image 74
MatsLindh Avatar answered Dec 05 '25 20:12

MatsLindh