On 8/9/2019 3:07 PM, Mark H. Wood wrote:
Did I miss something, or is there no way, using SolrJ, to enumerate
loaded cores, as:

   curl 'http://solr.example.com:8983/solr/admin/cores?action=STATUS'

does?

This code will do so.  I tested it.

public static void main(String[] args) throws SolrServerException, IOException {
    String url = "http://localhost:8983/solr";;
HttpSolrClient client = new HttpSolrClient.Builder().withBaseSolrUrl(url).build();
    CoreAdminRequest req = new CoreAdminRequest();
    req.setAction(CoreAdminAction.STATUS);
    CoreAdminResponse rsp = req.process(client);
    NamedList<Object> full = rsp.getResponse();
    NamedList<Object> status = (NamedList<Object>) full.get("status");
    int count = status.size();
    for (int i = 0; i < count; i++) {
      String coreName = status.getName(i);
      System.out.println("core: " + coreName);
    }
  }

It's possible that NamedList has a cleaner way of doing this. I went with what I know. :)

Note that the URL used to create the client object must end with /solr for this to work. If you try a URL that ends with /solr/corename it won't work. I like to use a client ending with /solr for *all* requests, and tell it what core I want the request to go to.

I would also not expect this to work with CloudSolrClient.

Thanks,
Shawn

Reply via email to