I have several Solr cores on the instance, each with a StandardRequestHandler and some custom request handlers configured, e.g.:
<requestDispatcher handleSelect="true" >
<requestParsers enableRemoteStreaming="false" multipartUploadLimitInKB="2048" />
</requestDispatcher>
...
<requestHandler name="standard" class="solr.StandardRequestHandler" default="true" />
...
<requestHandler name="/custom" class="com.example.our.package.CustomHandler" />
...
I'd like to be able to access both of them through SolrJ, however, I'm able to do this via only via setting the baseUrl property of the HttpSolrServer object. This is however not desirable, since the HttpSolrServer instance is shared between several threads, so race conditions would occur. Another reason is that the team's consensus lies in HttpSolrServer being Singleton-scoped for simplicity's sake.
What I tried is something like this:
HttpSolrServer server = new HttpSolrServer("http://URL_OF_SOLR:PORT/solr/");
SolrQuery query = new SolrQuery();
query.setQueryType("/core/custom");
This works for the custom handlers, however it fails with code 400 when calling /select, at least for the URLs I tried (/core, /core/select, /core/,/core/standard), etc.
So my question is: how should I define this query to correctly reference the core's default request handler, using only queryType or some other SolrParams value?
You an use the qt parameter in Solr to specify a specific request handler, even the default /select handler. See CoreQueryParameters for details on how this works. SolrJ supports this through the use of the setRequestHandler method on the SolrQuery class.
Some examples, assuming that your Solr instance is at http://localhost:8983/solr and you have two cores named core0 and core1.
http://localhost:8983/solr/core0/select?q=*:* this uses /select by defaulthttp://localhost:8983/sole/core1/select?q=*:*&qt=terms this uses the terms requestHandlerFinally the core name should not be included in the qt parameter b/c that parameter is designed to support selecting a named requestHandler within a core. The Url for the Solr instance should have the core name within it as each core is its own Solr instance and therefore should be treated as such, IMO. From the SolrCore wiki page:
Multiple cores let you have a single Solr instance with separate configurations and indexes, with their own config and schema for very different applications, but still have the convenience of unified administration.
So define multiple HttpSolrServer instances.
new HttpSolrServer(http://localhost:8983/solr/core0)
new HttpSolrServer(http://localhost:8983/solr/core1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With