Enumerating cores via SolrJ

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Enumerating cores via SolrJ

Mark H. Wood
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

signature.asc (201 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Enumerating cores via SolrJ

Brian Lininger
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 <[hidden email]> 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 *
[hidden email]
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.*
Reply | Threaded
Open this post in threaded view
|

Re: Enumerating cores via SolrJ

Shawn Heisey-2
In reply to this post by Mark H. Wood
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 | Threaded
Open this post in threaded view
|

Re: Enumerating cores via SolrJ

Mark H. Wood
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

signature.asc (201 bytes) Download Attachment