I am trying to connect to an instance of solr I have running on an EC2 Ubuntu AMI. I have opened the ports 7574, 8982, and 9983 for solr. I can see the console fine. I am using solrj to connect to my instance and trying to write a Solr doc with one field.
CloudSolrClient solr = new CloudSolrClient.Builder().withZkHost(external-ip:9983).build();
SolrInputDocument doc = new SolrInputDocument();
doc.addField("test", "test");
solr.add("collection", doc);
solr.commit();
From the Solr admin console I can see the empty collection. After 5 retries I get this error.
org.apache.solr.client.solrj.SolrServerException: No live SolrServers available to handle this request:[http://internal-ip:8983/solr/collection, http://internal-ip:7574/solr/collection]
Caused by: java.net.ConnectException: Connection timed out: connect
I am confused why the internal-ip is showing in the error message and why it cannot connect in general.
I started Solr with the command ./solr -e cloud -noprompt
Java 8
Looking at your question I suppose you're running Solr in AWS EC2 Instance and you're using Solrj to interact with Solr from your local computer.
The command ./solr -e cloud
launch a SolrCloud cluster on your local workstation. The network created by the script has a topology which is not compatible with your needs.
Starting Solr in standalone flavour (./solr start
) should let you to connect remotely with less pain.
In this case you have to use HttpSolrClient
:
String urlString = "http://remote-ec2-ip-address:8983/solr/yourcollection";
SolrClient solr = new HttpSolrClient.Builder(urlString).build();
When you start Solr in SolrCloud mode, the Solrj client use Zookeeper to discover Solr endpoints for SolrCloud collections.
But Zookeeper returns to the client a list of urls for each Solr instance and in your case these urls use an IP address that is are reachable only within the AWS network.
That's why you're unable to connect remotely.
Update
To be clear, in case you SolrCloud make sense only if you need an enterprise configuration, when you have millions of queries to serve and/or billions of documents to search into.
A cluster also means many EC2 instances usually 3 (or more) Solr Instances and 3 (or 5) Zookeeper instances.