buy clomid online

Jan 20

[Solr] get list cores from your RequestHandler

Category: geek,java

In Solr, RequestHandler are called from a specific core.
But, there is many cases where we want to have more information from other cores.

The easist way is to get this information directly from the the request parameter. Indeed, in your handleRequestBody:

  1. @Override
  2. public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {

Get your current core.

  1. final SolrCore core = req.getCore();

Retrieve CoreContainer using core object.
CoreContainer contain all cores, so, can be used easily to get all cores.

  1. final Collection<SolrCore> cores = core.getCoreDescriptor().getCoreContainer().getCores();

A loop can be used to display our cores.

  1. for (SolrCore solrCore : cores) {
  2.     log.info(solrCore.getName());
  3. }

😉 you can call a get to retrieve a specific core

  1. SolrCore core1 = core.getCoreDescriptor().getCoreContainer().getCore("core1");

Update : Don’t forget to close your core after exploitation with core.close()

2 comments

2 Comments so far

  1. Benjamin January 15th, 2015 2:26 pm

    Be care of CoreContainer().getCore(“…”) because it will increase core ref’ counts. Do not forgot to core.close()

  2. nihed January 19th, 2015 11:03 am

    Thank you for this information

Leave a comment