Class CloudSolrClient

  • All Implemented Interfaces:
    Closeable, Serializable, AutoCloseable

    public class CloudSolrClient
    extends SolrClient
    SolrJ client class to communicate with SolrCloud. Instances of this class communicate with Zookeeper to discover Solr endpoints for SolrCloud collections, and then use the LBHttpSolrClient to issue requests. This class assumes the id field for your documents is called 'id' - if this is not the case, you must set the right name with setIdField(String).
    See Also:
    Serialized Form
    • Field Detail

      • collectionStateCache

        protected final org.apache.solr.client.solrj.impl.CloudSolrClient.StateCache collectionStateCache
    • Constructor Detail

      • CloudSolrClient

        protected CloudSolrClient​(CloudSolrClient.Builder builder)
        Create a new client object that connects to Zookeeper and is always aware of the SolrCloud state. If there is a fully redundant Zookeeper quorum and SolrCloud has enough replicas for every shard in a collection, there is no single point of failure. Updates will be sent to shard leaders by default.
        builder - a CloudSolrClient.Builder with the options used to create the client.
    • Method Detail

      • setRetryExpiryTime

        public void setRetryExpiryTime​(int secs)
        This is the time to wait to refetch the state after getting the same state version from ZK


      • setCollectionCacheTTl

        public void setCollectionCacheTTl​(int seconds)
        Sets the cache ttl for DocCollection Objects cached . This is only applicable for collections which are persisted outside of clusterstate.json
        seconds - ttl value in seconds
      • setParser

        public void setParser​(ResponseParser processor)
        Note: This setter method is not thread-safe.
        processor - Default Response Parser chosen to parse the response if the parser were not specified as part of the request.
        See Also:
      • setRequestWriter

        public void setRequestWriter​(RequestWriter requestWriter)
      • getZkHost

        public String getZkHost()
        the zkHost value used to connect to zookeeper.
      • setIdField

        public void setIdField​(String idField)
        idField - the field to route documents on.
      • getIdField

        public String getIdField()
        the field that updates are routed on.
      • setDefaultCollection

        public void setDefaultCollection​(String collection)
        Sets the default collection for request
      • getDefaultCollection

        public String getDefaultCollection()
        Gets the default collection for request
      • setZkConnectTimeout

        public void setZkConnectTimeout​(int zkConnectTimeout)
        Set the connect timeout to the zookeeper ensemble in ms
      • setZkClientTimeout

        public void setZkClientTimeout​(int zkClientTimeout)
        Set the timeout to the zookeeper ensemble in ms
      • isParallelUpdates

        public boolean isParallelUpdates()
        Gets whether direct updates are sent in parallel
      • connect

        public void connect()
        Connect to the zookeeper ensemble. This is an optional method that may be used to force a connect before any other requests are sent.
      • connect

        public void connect​(long duration,
                            TimeUnit timeUnit)
                     throws TimeoutException,
        Connect to a cluster. If the cluster is not ready, retry connection up to a given timeout.
        duration - the timeout
        timeUnit - the units of the timeout
        TimeoutException - if the cluster is not ready after the timeout
        InterruptedException - if the wait is interrupted
      • registerCollectionStateWatcher

        public void registerCollectionStateWatcher​(String collection,
                                                   CollectionStateWatcher watcher)
        Register a CollectionStateWatcher to be called when the cluster state for a collection changes Note that the watcher is unregistered after it has been called once. To make a watcher persistent, it should re-register itself in its CollectionStateWatcher.onStateChanged(Set, DocCollection) call
        collection - the collection to watch
        watcher - a watcher that will be called when the state changes
      • getHttpClient

        public org.apache.http.client.HttpClient getHttpClient()
      • isUpdatesToLeaders

        public boolean isUpdatesToLeaders()
      • isDirectUpdatesToLeadersOnly

        public boolean isDirectUpdatesToLeadersOnly()
        true if direct updates are sent to shard leaders only
      • setParallelCacheRefreshes

        public void setParallelCacheRefreshes​(int n)
        If caches are expired they are refreshed after acquiring a lock. use this to set the number of locks
      • getMinAchievedReplicationFactor

        public int getMinAchievedReplicationFactor​(String collection,
                                                   NamedList resp)
        Useful for determining the minimum achieved replication factor across all shards involved in processing an update request, typically useful for gauging the replication factor of a batch.
      • getShardReplicationFactor

        public Map<String,​Integer> getShardReplicationFactor​(String collection,
                                                                   NamedList resp)
        Walks the NamedList response after performing an update request looking for the replication factor that was achieved in each shard involved in the request. For single doc updates, there will be only one shard in the return value.