Search code examples
solrsolrj

Retrieve schema info from HttpSolrServer and CloudSolrServer with SolrJ


HttpSolrServer/CloudSolrServer support the /schema request handler but that isn't supported on the EmbeddedSolrServer and I would like a way to access the same information using SolrJ (and without HTTP requests).

When using EmbeddedSolrServer, the instance is created by passing a CoreContainer to the constructor. Later, the CoreContainer can be queried for all (well, just the one in the case of an embedded server) SolrCores with the getCores() method. From any given SolrCore I can obtain its schema using getSchema().

I now want to do the same thing but with an HttpSolrServer server and a CloudSolrServer. They, however, don't seem to have a way to ask for the list of loaded SolrCores or CoreContainers or anything. I know about the CoreAdmin but that only retrieves the status of each core, with no way to get Java instances of SolrCore.

Is it possible to obtain a list of SolrCores from a HttpSolrServer/CloudSolrServer using SolrJ, and how is it done?


Solution

  • Since Solr 5.3 SolrJ has API for Schema Access - see SchemaRequest.

    For example, to retrieve collection schema one can use (in Solr 7) :

    CloudSolrClient client = ...;
    SchemaRequest request = new SchemaRequest();
    SchemaResponse response = request.process(client, "collectionName");
    SchemaRepresentation schema = response.getSchemaRepresentation();