What is the default address of Solr Server (Solr 4.0) for use from a SolrJ client - solr

I'm trying to connect with Solr Server from a SolrJ client, but it gives an HTTPResponse Exception.
Here's my code:
SolrServer server = new HttpSolrServer("http://"localhost":8983/solr/");
Here's the exception:
java.lang.NoClassDefFoundError: org/apache/http/NoHttpResponseException:
Does Solr have a default address? Where can you find it?

I am not familiar with SolrJ - but the endpoint seems to be missing the core name to me.
You would need to point your Solr client to a particular core.
The URI for the core would look like this (for reloading core command)
http://localhost:8983/solr/{{solrCoreName}}
The admin UI should be accessible at
http://localhost:8983/solr

By default, Solr will start on port 8983. That can be changed though. You can change that for example in the solr.in.sh file using the SOLR_PORT property.

Related

SolrJ : Server refused connection

For a customer, I need to write a search engine running on Linux. I am using SolrJ and did not configure anything else so far.
I followed https://lucene.apache.org/solr/guide/7_4/using-solrj.html#common-build-systems and thus added SolrJ in the project pom.xml, and also that tutorial.
The SolR client is instanciated like :
solrClient = new HttpSolrClient.Builder(
GeneralSettings.getRootSolrPath() + "/" + getCollectionName()).
build();
But for any query or commit I keep getting org.apache.solr.client.solrj.SolrServerException: Server refused connection at: http://localhost:8983/solr/test. I read http://lucene.472066.n3.nabble.com/Default-query-error-quot-Server-refused-connection-quot-td4010806.html but I am already using the expected port.
My understanding of the java doc SolrClient ’s handle the work of connecting to and communicating with Solr, and are where most of the user configuration happens. is that I only need to import the jar and then everything will work out of the box.
But as I keep getting this "Server refused connection" error I may have to configure something, but I could not find how to configure SolrJ (use solrconfig.xml or core.properties or call System.setProperty or call an API).
Please note that Apache may be running somewhere because I used to test some sites on it.
So how to get rid of this "Server refused connection" error?
Any help or tutorial to set SolrJ up based on Solr available doc would be very much appreciated,
Edit 2018-08-12 16:10
I thought SolrJ could work like Lucene, without a server, but it looks that I missed one essential piece: installing Solr (see https://www.baeldung.com/apache-solrj). I'll give it a try and post updates.
In case it might help someone else starting with SolrJ here are the steps I did to get rid of the error mentionned in the title (actually I followed https://www.baeldung.com/apache-solrj).
Downloaded the latest binary release of Solr
Extracted it somewhere
CDed into that dir
Lauched bin/solr start from that dir
Created a core with bin/solr create -c coreName (maybe another way exists but I hadn't been able to make it work so far)
Then Solr was running and listening on port 8983, and my Java app could connect to it via SolrJ.

CloudSolrServer in Solr 7.3

I am new to Solr.
I want to build CloudSolrServerin Solr 7.3. However, I do not find CloudSolrServer in source code and API doc, but I do find CloudSolrClient.
Is CloudSolrServer deprecated? What's the new class name?
import org.apache.solr.client.solrj.impl.{CloudSolrClient(found), CloudSolrServer(cannot resolve symbol)}
yes it is deprecated, CloudSolrClient replaces it. It was just a better name, as this is the client to connect to Solr server.

Not able to connect to SOLR through CloudSolrClient?

I am facing some issue while connecting to Solr through CloudSolrClient. I used the following piece of code.
CloudSolrClient server = new CloudSolrClient("ip:8983");
server.setDefaultCollection("hadoop_logs_shard3_replica1");
I am getting following error
java.io.IOException: Packet len1213486160 is out of range!
at org.apache.zookeeper.ClientCnxnSocket.readLength(ClientCnxnSocket.java:112)
at org.apache.zookeeper.ClientCnxnSocketNIO.doIO(ClientCnxnSocketNIO.java:79)
at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:366)
at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1081)
public CloudSolrClient(String zkHost)
Create a new client object that connects to Zookeeper and is always aware of the SolrCloud state. Updates will be sent to shard leaders by default.
You are specifying solr instance host:port instead of zookeeper host:port. Fix that, It should work afterwards.
1213486160 is ASCII "HTTP" interpreted as a 32-bit big-endian integer. As YoungHobbit suggests, you are not speaking to the correct service.

Retrieve schema info from HttpSolrServer and CloudSolrServer with SolrJ

HttpSolrServer/CloudSolrServer support the /schema request handler but that isn't supported on the EmbeddedSolrServer and I would like a way to access the same information using SolrJ (and without HTTP requests).
When using EmbeddedSolrServer, the instance is created by passing a CoreContainer to the constructor. Later, the CoreContainer can be queried for all (well, just the one in the case of an embedded server) SolrCores with the getCores() method. From any given SolrCore I can obtain its schema using getSchema().
I now want to do the same thing but with an HttpSolrServer server and a CloudSolrServer. They, however, don't seem to have a way to ask for the list of loaded SolrCores or CoreContainers or anything. I know about the CoreAdmin but that only retrieves the status of each core, with no way to get Java instances of SolrCore.
Is it possible to obtain a list of SolrCores from a HttpSolrServer/CloudSolrServer using SolrJ, and how is it done?
Since Solr 5.3 SolrJ has API for Schema Access - see SchemaRequest.
For example, to retrieve collection schema one can use (in Solr 7) :
CloudSolrClient client = ...;
SchemaRequest request = new SchemaRequest();
SchemaResponse response = request.process(client, "collectionName");
SchemaRepresentation schema = response.getSchemaRepresentation();

Carrot2 dcs webapp setup

I have been struggling with setting up Carrot2 for use PHP, on a local machine. The plan is to have Carrot2 retrieve cluster from Solr populated by Nutch. Currently Solr and Nutch are correctly configured and I have been able to access the information via Carrot2 Workbench. Carrot2-dcs-3.10.0 has been set up what I believed to be correctly deployed through the tomcat6 manager although the documentation on setting this up is horrible vague and incomplete. Changes to source-solr-attributes.xml were made according to https://sites.google.com/site/profileswapnilkulkarni/tech-talk/howtoconfigureandruncarrot2webapplicationwithsolrdocumentsource . Tomcat is set up on port 8080. The Carrot2 DCS php example example.php works and displays the test output correctly. Although, when I try to perform a cluster using localIPAddress:8080/carrot2-dcs/index.html I run into a problem. When I set document source to Solr and the query to : then click cluster I get the following error message.
HTTP Status 500 - Could not perform processing: org.apache.http.conn.HttpHostConnectException: Connection to localhost:8983 refused
type Status report
message Could not perform processing: org.apache.http.conn.HttpHostConnectException: Connection to localhost:8983 refused
description The server encountered an internal error that prevented it from fulfilling this request.
I have searched everywhere in the deployed webapp folder for carrot2 and can't find where it is getting localhost:8983 from.
Any assistance would be appreciated, thank you.
It turns out that the source-solr-attributes.xml file had an extra overridden-attributes. one was before the default block comment with the example parameters and the second was added in by me with the parameters needed for my config. Deleting one of the line so there was only one corrected the problem. Apparently with two of those it ignores the server settings and uses default values instead.

Resources