Search code examples
javasolrsolrj

How to check which IP addresses of different shards for each index are up and functioning in a Solr server using SolrJ


Given just the HTTP URL of a Solr server, I have to check all the IP addresses and ports where the server stores the data in shards and then return any IP servers which are down and not functioning.

I have to do this by writing a Java code in Eclipse. I found a Java API SolrJ which can query the Solr database but I'm not sure how to get all the shards and their IP addresses. Any piece of code or process will be of much help.


Solution

  • You could use Collections API calls in SolrJ to be able to request cluster status, that means also live nodes, etc.

    One could do something like this:

    final SolrClient client = getSolrClient();
    
    final SolrRequest request = new CollectionAdminRequest.ClusterStatus();
    
    final NamedList<Object> response = client.request(request);
    final NamedList<Object> cluster = (NamedList<Object>) response.get("cluster");
    final List<String> liveNodes = (List<String>) cluster.get("live_nodes");
    
    print("Found " + liveNodes.size() + " live nodes");
    

    More information about it - https://lucene.apache.org/solr/guide/7_3/using-solrj.html#other-apis