A Dev
A Dev

Reputation: 321

SolrJ connect to Solr from Java

I'm trying to connect from my Java code to a Solr server running 5.3.1 using the same version of SolrJ. I keep getting a message in Eclipse that HttpSolrServer is deprecated, but cannot find anywhere what it has been replaced with. Does anyone know how I can connect to Solr from Java using SolrJ using something current? The SolrJ documentation all seems to suggest that HttpSolrServer is the supported way, but Eclipse is not happy about it.

Upvotes: 0

Views: 5539

Answers (4)

Sleiman Jneidi
Sleiman Jneidi

Reputation: 23329

Eclipse marks every class that has @Deprecated annotation as deprecated.
HttpSolrServer was deprecated indeed and HttpSolrClient is its replacment

SolrClient solrClient = new HttpSolrClient.Builder(solrLocation).build();

Upvotes: 1

Divyang Shah
Divyang Shah

Reputation: 1668

deprecated:

SolrClient client = new HttpSolrClient(solrLocation);

use this:

SolrClient client = new HttpSolrClient.Builder(solrLocation).build();

Upvotes: 0

freedev
freedev

Reputation: 30067

Starting from Solr 6.1 this the preferred way with to create SolrJ HTTP client:

String urlString = "http://localhost:8983/solr/my-collection";
SolrClient solrClient = new HttpSolrClient.Builder(urlString).build();

http://lucene.apache.org/solr/6_5_0/solr-solrj/org/apache/solr/client/solrj/impl/HttpSolrClient.Builder.html

Upvotes: 2

Victor
Victor

Reputation: 781

public class SolrCient {

private static final Logger LOGGER = Logger.getLogger(SolrCient.class.getName());

private static final String SERVER_URL = "http://localhost:8983/solr/suggest";

public static void main(String[] args) throws IOException, SolrServerException {

    HttpSolrClient solr = new HttpSolrClient(SERVER_URL);

    QueryResponse  response = solr.query(new SolrQuery("*:*"));

    System.out.println(response.toString());

}

}

Upvotes: 0

Related Questions