2

I'm unable to connect to my Solr instance on Tomcat from SolrJ. I've been through the documentation shown at "http://wiki.apache.org/solr/Solrj" , but its pretty outdated - primarily because it has no reference on Solr cores. I'm wondering if somebody could point me to the latest documentation OR advise on how to connect SolrJ with Solr4.0 or ahead - although my instance is running just 1 core for now.

Here's my connection string: "localhost:8080/solr-example/collection1/". Do you know which jars to add along with solrj? Thats where the trouble might be. For examples, the SolrJ wiki references a jar called commons-codec-1.3.jar which is not to be found anywhere, in the solr 4.0 zip file.

EternallyCurious
  • 2,345
  • 7
  • 47
  • 78
  • 1
    What errors exactly are you getting? – phisch Apr 28 '13 at 07:51
  • It shows an HttpResponseException if connected the way shown in the existing documentation. I had asked another question, regarding this earlier, but the problem wasn't solved: http://stackoverflow.com/questions/16129222/what-is-the-default-address-of-solr-server-solr-4-0-for-use-from-a-solrj-clien – EternallyCurious Apr 28 '13 at 08:15
  • Please Update your question with the exact error message. Can you browse the WebAdmin of Solr? – phisch Apr 28 '13 at 08:51

1 Answers1

4

Calling Solr from Java with SolrJ

You can specify the Core directly in the URL.

HttpSolrServer server = new HttpSolrServer("http://localhost:8080/solr/my_core");

SolrQuery solrQuery = new SolrQuery();
solrQuery.setQuery(q);
solrQuery.setStart(start);
solrQuery.setRows(rows);

QueryResponse response = server.query(solrQuery);

HttpSolrServer is reusable for more queries.

The communication between the Solr Server and SolrJ happens via HTTP with a custom binary format. Can you Browse the Solr Web Admin at http://localhost:8080/solr? Depending on your installation, you might need to adjust the port (8080 is default on Tomcat, jetty uses 8983).

Also, did you deploy Solr with a generic name or did you include the Version? Than your URL would be http://localhost:8080/solr-4.2.1/my_core

Dependencies

These are the minimum dependencies you need for using SolrJ. Add these to your pom.xml, if you are using maven.

<dependency>
  <artifactId>solr-solrj</artifactId>
  <groupId>org.apache.solr</groupId>
  <version>4.2.0</version>
  <type>jar</type>
  <scope>compile</scope>
</dependency>
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-simple</artifactId>
  <version>1.5.6</version>
</dependency>
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-api</artifactId>
  <version>1.7.2</version>
</dependency>
<dependency>
  <groupId>commons-logging</groupId>
  <artifactId>commons-logging</artifactId>
  <version>1.1.1</version>
</dependency>

If you are not using maven, you need the following jars:

  • solr-solrj-4.2.0
  • zookeeper-3.4.5
  • commons-io-2.1
  • httpclient-4.2.3
  • httpcore-4.2.2
  • commons-codec-1.6
  • httpmime-4.2.3
  • wstx-asl-3.2.3
  • slf4j-simple-1.5.6
  • slf4j-api-1.7.2
  • commons-logging-1.1.1
phisch
  • 4,571
  • 2
  • 34
  • 52
  • Here's my connection string: "http://localhost:8080/solr-example/collection1/". Do you know which jars to add along with solrj? Thats where the trouble might be. For examples, the SolrJ wiki references a jar called commons-codec-1.3.jar which is not to be found anywhere, in the solr 4.0 zip file. – EternallyCurious Apr 28 '13 at 08:53
  • Please add those details to your original question so that every one can see them without having to read all comments. – phisch Apr 28 '13 at 08:58
  • Just curious where you fond this list? Could you point me please? Thanks. – EternallyCurious Apr 28 '13 at 10:35
  • The list is generated from the maven dependencies, including all derived dependencies. – phisch Apr 28 '13 at 10:42