Solrj Select All

I'm having trouble choosing everything in my Solr index (3.6) in 25 documents via Solrj (running Tomcat).

public static void main(String[] args) throws MalformedURLException, SolrServerException { SolrServer solr = new HttpSolrServer("http://localhost:8080/solr"); ModifiableSolrParams parameters = new ModifiableSolrParams(); parameters.set("?q", "*:*"); parameters.set("wt", "json"); QueryResponse response = solr.query(parameters); System.out.println(response); } 

The result is:

 {responseHeader={status=0,QTime=0,params={?q=*:*,wt=javabin,version=2}},response={numFound=0,start=0,docs=[]}} 

Also, if I take the "?" from parameters.set("?q", "*:*"); I need to stop compiling, otherwise it will end. The same thing happens if I replaced

 "*:*" 

with just

 "*" 

In addition, I tried parameters.set("qt", "/select"); to no avail.

How do you select everything and get results through Solrj?

0
source share
3 answers

I'm not sure why this works, but after failing a hundred ideas, it took:

 public static void main(String[] args) throws MalformedURLException, SolrServerException { SolrServer solr = new HttpSolrServer("http://localhost:8080/solr"); ModifiableSolrParams parameters = new ModifiableSolrParams(); parameters.set("q", "*:*"); //query everything thanks to user1452132! parameters.set("facet", true);//without this I cant select all parameters.set("fl", "id");//send back just the id values parameters.set("wt", "json");//Id like this in json format please QueryResponse response = solr.query(parameters); System.out.println(response); } 

Hope this helps someone out there.

+2
source

You must use "q" as the parameter, and the next is the correct syntax.

 parameters.set("?q", "*:*"); 

The reason it returns with "? Q" is because the request does not start, so it returns quickly.

First check the test through the browser. You can also set the number of rows to return so that you do not return a large set of results.

 parameters.set("rows", 5); 

Once the solr request returns, you must paginate through the results. If you had a large collection, you won’t be able to get them all in one go.

+1
source

I think you should try to also indicate your kernel whenever you access the SolrServer object, i.e. write

 SolrServer solr = new HttpSolrServer("http://localhost:8080/solr/collection1"); 

where collection1 is the name of the kernel you want to use.

0
source

All Articles