You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by "Mark H. Wood" <mw...@iupui.edu> on 2019/08/09 21:07:23 UTC

Enumerating cores via SolrJ

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?

-- 
Mark H. Wood
Lead Technology Analyst

University Library
Indiana University - Purdue University Indianapolis
755 W. Michigan Street
Indianapolis, IN 46202
317-274-0749
www.ulib.iupui.edu

Re: Enumerating cores via SolrJ

Posted by Brian Lininger <br...@veeva.com>.
You can extend  org.apache.solr.client.solrj.request.CoreAdminRequest to do
exactly what you're asking for....

On Fri, Aug 9, 2019 at 2:07 PM Mark H. Wood <mw...@iupui.edu> 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?
>
> --
> Mark H. Wood
> Lead Technology Analyst
>
> University Library
> Indiana University - Purdue University Indianapolis
> 755 W. Michigan Street
> Indianapolis, IN 46202
> 317-274-0749
> www.ulib.iupui.edu
>


-- 


*Brian Lininger*
Technical Architect, Infrastructure & Search
*Veeva Systems *
brian.lininger@veeva.com
www.veeva.com

*This email and the information it contains are intended for the intended
recipient only, are confidential and may be privileged information exempt
from disclosure by law.*
*If you have received this email in error, please notify us immediately by
reply email and delete this message from your computer.*
*Please do not retain, copy or distribute this email.*

Re: Enumerating cores via SolrJ

Posted by "Mark H. Wood" <mw...@iupui.edu>.
On Fri, Aug 09, 2019 at 03:45:21PM -0600, Shawn Heisey wrote:
> 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.
[snip]

Thank you.  That was just the example I needed.

-- 
Mark H. Wood
Lead Technology Analyst

University Library
Indiana University - Purdue University Indianapolis
755 W. Michigan Street
Indianapolis, IN 46202
317-274-0749
www.ulib.iupui.edu

Re: Enumerating cores via SolrJ

Posted by Shawn Heisey <ap...@elyograg.org>.
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