1

I have a solr instance running and am able to access it through the browser and use the Admin to run queries. When I try to access it via Java code in Eclipse, however, I receive the following error:

Exception in thread "main" org.apache.solr.common.SolrException: Server at   http://localhost:8983/solr returned non ok status:404, message:Not Found
at org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:372)
at org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:181)
at org.apache.solr.client.solrj.request.QueryRequest.process(QueryRequest.java:90)
at org.apache.solr.client.solrj.SolrServer.query(SolrServer.java:301)
at testClass.main(testClass.java:18)

Here is the code I am running:

public static void main(String[] args) throws MalformedURLException, SolrServerException {
    SolrServer server = new HttpSolrServer("http://localhost:8983/solr/");
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set("myParam", "myValue");
    QueryResponse response = server.query(params);
}
vincentvanjoe
  • 767
  • 1
  • 12
  • 23

2 Answers2

1

It turns out that I had two errors:

1) My setup actually has a nested solr directory so I needed to add another "solr" level.

2) I was setting the params variable incorrectly. The first argument sent should be "q", with the second argument being the "name:value" pairs.

Updated example, includes passing multiple params at once:

public static void main(String[] args) throws MalformedURLException, SolrServerException {
    SolrServer server = new HttpSolrServer("http://localhost:8983/solr/solr/");
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set("q", "param1:value1 AND param2:value2");
    QueryResponse response = server.query(params);
    System.out.println("response = " + response);
}
vincentvanjoe
  • 767
  • 1
  • 12
  • 23
0

shouldn't it be :-

 SolrServer server = new HttpSolrServer("http://localhost:8983/solr");

See the accepted answer in the following link :-

Querying Solr via Solrj: Basics

Community
  • 1
  • 1
Max
  • 4,067
  • 1
  • 18
  • 29