what about just calling:
http://doom:8983/solr/content_item_representations_20081201/select

That should give you a 404 if it does not exist.

the admin stuff will behave funny if the core does not exist (perhaps you can file a JIRA issue for that)

ryan


On Dec 4, 2008, at 3:38 PM, Dean Thompson wrote:

The ping command gives me a 500 status if the core exists, or a 404 if it doesn't. For example, when I hit

   http://doom:8983/solr/content_item_representations_20081201/admin/ping

I see

   HTTP ERROR: 500

   INTERNAL_SERVER_ERROR

   RequestURI=/solr/admin/ping

   Powered by Jetty://

(Obviously I'm using Jetty.  Moving to Tomcat is on our list.)

I could depend on this behavior, but that seems ugly, so I decided to try a "probe query" instead.

I am using the Solrj client library. Unfortunately, for core non- existence or any other problem, Solrj uses an unhelpful catch-all exception:

/** Exception to catch all types of communication / parsing issues associated with talking to SOLR
     *
* @version $Id: SolrServerException.java 555343 2007-07-11 17:46:25Z hossman $
     * @since solr 1.3
     */
   public class SolrServerException extends Exception {
       ...
   }

So I have wound up, thus far, with the following code:

   private boolean solrCoreExists(String url)
throws SolrException, MalformedURLException, SolrServerException
   {
       try {
           SolrQuery solrQuery = new SolrQuery();
           solrQuery.setQuery("xyzzy=plugh");
           new CommonsHttpSolrServer(url).query(solrQuery);
           return true;
       } catch (SolrServerException e) {
if (e.getCause() != null && e.getCause().getMessage().startsWith("Not Found")) {
               return false;
           } else {
               throw e;
           }
       }
   }

Hopefully there's a better solution?

Dean


Reply via email to