On 11/4/2015 12:52 PM, tedsolr wrote:
> I'm wondering what the best practice is for the implementations of
> SolrClient: CloudSolrClient & HttpSolrClient. I am caching my clients per
> collection (core) and reusing them right now. Initially this was prompted by
> the old  solr wiki page <https://wiki.apache.org/solr/Solrj>   and SOLR-861.
> Is that still a good idea? Is that better than creating new ones over and
> over and remembering to call close() after each use?

You should definitely reuse the client objects, ideally for the entire
life of your application, rather than close them and create new
objects.  The client objects are completely threadsafe, so you don't
need dedicated objects for each thread.

In 5.x, not sure which specific release but 5.2.1 definitely has it, you
can reduce your client creation to one CloudSolrClient per cloud or one
HttpSolrClient per server, because there are a bunch of new methods that
let you tell SolrJ which core/collection you want to target.  Here's one
of those new methods:

https://lucene.apache.org/solr/5_2_1/solr-solrj/org/apache/solr/client/solrj/SolrClient.html#query%28java.lang.String,%20org.apache.solr.common.params.SolrParams%29

When creating the HttpSolrClient object, you just end the URL with
"/solr" instead of "/solr/corename" to allow these new methods to work. 
The constructor for CloudSolrClient won't be any different, since that
talks to zookeeper.

Thanks,
Shawn

Reply via email to