public class CloudSolrClient extends SolrClient
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)
.Modifier and Type | Class and Description |
---|---|
static class |
CloudSolrClient.Builder
Constructs
CloudSolrClient instances from provided configuration. |
static class |
CloudSolrClient.RouteException |
static class |
CloudSolrClient.RouteResponse |
Modifier and Type | Field and Description |
---|---|
protected Map<String,org.apache.solr.client.solrj.impl.CloudSolrClient.ExpiringCachedDocCollection> |
collectionStateCache |
static String |
STATE_VERSION |
Constructor and Description |
---|
CloudSolrClient(Collection<String> zkHosts,
String chroot)
Deprecated.
use
CloudSolrClient.Builder instead. |
CloudSolrClient(Collection<String> zkHosts,
String chroot,
org.apache.http.client.HttpClient httpClient)
Deprecated.
use
CloudSolrClient.Builder instead. |
CloudSolrClient(Collection<String> zkHosts,
String chroot,
org.apache.http.client.HttpClient httpClient,
LBHttpSolrClient lbSolrClient,
boolean updatesToLeaders)
Deprecated.
use
CloudSolrClient.Builder instead. This will soon be a protected method, and will only
be available for use in implementing subclasses. |
CloudSolrClient(String zkHost)
Deprecated.
use
CloudSolrClient.Builder instead. |
CloudSolrClient(String zkHost,
boolean updatesToLeaders)
Deprecated.
use
CloudSolrClient.Builder instead. |
CloudSolrClient(String zkHost,
boolean updatesToLeaders,
org.apache.http.client.HttpClient httpClient)
Deprecated.
use
CloudSolrClient.Builder instead. |
CloudSolrClient(String zkHost,
org.apache.http.client.HttpClient httpClient)
Deprecated.
use
CloudSolrClient.Builder instead. |
CloudSolrClient(String zkHost,
LBHttpSolrClient lbClient)
Deprecated.
use
CloudSolrClient.Builder instead. |
CloudSolrClient(String zkHost,
LBHttpSolrClient lbClient,
boolean updatesToLeaders)
Deprecated.
use
CloudSolrClient.Builder instead. |
Modifier and Type | Method and Description |
---|---|
void |
close() |
CloudSolrClient.RouteResponse |
condenseResponse(NamedList response,
int timeMillis) |
void |
connect()
Connect to the zookeeper ensemble.
|
void |
connect(long duration,
TimeUnit timeUnit)
Connect to a cluster.
|
void |
downloadConfig(String configName,
Path downloadPath)
Download a named config from Zookeeper to a location on the filesystem
|
String |
getDefaultCollection()
Gets the default collection for request
|
protected DocCollection |
getDocCollection(ClusterState clusterState,
String collection,
Integer expectedVersion) |
org.apache.http.client.HttpClient |
getHttpClient() |
String |
getIdField() |
LBHttpSolrClient |
getLbClient() |
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.
|
ResponseParser |
getParser() |
RequestWriter |
getRequestWriter() |
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.
|
String |
getZkHost() |
ZkStateReader |
getZkStateReader() |
boolean |
isDirectUpdatesToLeadersOnly() |
boolean |
isUpdatesToLeaders() |
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.
|
NamedList<Object> |
request(SolrRequest request,
String collection)
Execute a request against a Solr server for a given collection
|
protected NamedList<Object> |
requestWithRetryOnStaleState(SolrRequest request,
int retryCount,
String collection)
As this class doesn't watch external collections on the client side,
there's a chance that the request will fail due to cached stale state,
which means the state must be refreshed from ZK and retried.
|
protected NamedList<Object> |
sendRequest(SolrRequest request,
String collection) |
void |
setCollectionCacheTTl(int seconds)
Sets the cache ttl for DocCollection Objects cached .
|
void |
setDefaultCollection(String collection)
Sets the default collection for request
|
void |
setIdField(String idField) |
void |
setParallelCacheRefreshes(int n)
If caches are expired they are refreshed after acquiring a lock.
|
void |
setParallelUpdates(boolean parallelUpdates) |
void |
setParser(ResponseParser processor)
Note: This setter method is not thread-safe.
|
void |
setRequestWriter(RequestWriter requestWriter) |
void |
setSoTimeout(int timeout) |
void |
setZkClientTimeout(int zkClientTimeout)
Set the timeout to the zookeeper ensemble in ms
|
void |
setZkConnectTimeout(int zkConnectTimeout)
Set the connect timeout to the zookeeper ensemble in ms
|
void |
uploadConfig(Path configPath,
String configName)
Upload a set of config files to Zookeeper and give it a name
NOTE: You should only allow trusted users to upload configs.
|
void |
waitForState(String collection,
long wait,
TimeUnit unit,
CollectionStatePredicate predicate)
Block until a collection state matches a predicate, or a timeout
Note that the predicate may be called again even after it has returned true, so
implementors should avoid changing state within the predicate call itself.
|
add, add, add, add, add, add, add, add, add, add, addBean, addBean, addBean, addBean, addBeans, addBeans, addBeans, addBeans, addBeans, addBeans, commit, commit, commit, commit, commit, commit, deleteById, deleteById, deleteById, deleteById, deleteById, deleteById, deleteById, deleteById, deleteByQuery, deleteByQuery, deleteByQuery, deleteByQuery, getBinder, getById, getById, getById, getById, getById, getById, getById, getById, optimize, optimize, optimize, optimize, optimize, optimize, ping, query, query, query, query, queryAndStreamResponse, queryAndStreamResponse, request, rollback, rollback
public static final String STATE_VERSION
@Deprecated public CloudSolrClient(String zkHost)
CloudSolrClient.Builder
instead.zkHost
- The client endpoint of the zookeeper quorum containing the cloud
state. The full specification for this string is one or more comma
separated HOST:PORT values, followed by an optional chroot value
that starts with a forward slash. Using a chroot allows multiple
applications to coexist in one ensemble. For full details, see the
Zookeeper documentation. Some examples:
"host1:2181"
"host1:2181,host2:2181,host3:2181/mysolrchroot"
"zoo1.example.com:2181,zoo2.example.com:2181,zoo3.example.com:2181"
@Deprecated public CloudSolrClient(String zkHost, org.apache.http.client.HttpClient httpClient)
CloudSolrClient.Builder
instead.zkHost
- The client endpoint of the zookeeper quorum containing the cloud
state. The full specification for this string is one or more comma
separated HOST:PORT values, followed by an optional chroot value
that starts with a forward slash. Using a chroot allows multiple
applications to coexist in one ensemble. For full details, see the
Zookeeper documentation. Some examples:
"host1:2181"
"host1:2181,host2:2181,host3:2181/mysolrchroot"
"zoo1.example.com:2181,zoo2.example.com:2181,zoo3.example.com:2181"
httpClient
- the HttpClient
instance to be used for all requests. The
provided httpClient should use a multi-threaded connection manager.@Deprecated public CloudSolrClient(Collection<String> zkHosts, String chroot)
CloudSolrClient.Builder
instead.CloudSolrClient(String)
instead.zkHosts
- A Java Collection (List, Set, etc) of HOST:PORT strings, one for
each host in the zookeeper ensemble. Note that with certain
Collection types like HashSet, the order of hosts in the final
connect string may not be in the same order you added them.chroot
- A chroot value for zookeeper, starting with a forward slash. If no
chroot is required, use null.IllegalArgumentException
- if the chroot value does not start with a forward slash.CloudSolrClient(String)
@Deprecated public CloudSolrClient(Collection<String> zkHosts, String chroot, org.apache.http.client.HttpClient httpClient)
CloudSolrClient.Builder
instead.CloudSolrClient(String)
instead.zkHosts
- A Java Collection (List, Set, etc) of HOST:PORT strings, one for
each host in the zookeeper ensemble. Note that with certain
Collection types like HashSet, the order of hosts in the final
connect string may not be in the same order you added them.chroot
- A chroot value for zookeeper, starting with a forward slash. If no
chroot is required, use null.httpClient
- the HttpClient
instance to be used for all requests. The provided httpClient should use a
multi-threaded connection manager.IllegalArgumentException
- if the chroot value does not start with a forward slash.CloudSolrClient(String)
@Deprecated public CloudSolrClient(Collection<String> zkHosts, String chroot, org.apache.http.client.HttpClient httpClient, LBHttpSolrClient lbSolrClient, boolean updatesToLeaders)
CloudSolrClient.Builder
instead. This will soon be a protected method, and will only
be available for use in implementing subclasses.zkHosts
- A Java Collection (List, Set, etc) of HOST:PORT strings, one for
each host in the zookeeper ensemble. Note that with certain
Collection types like HashSet, the order of hosts in the final
connect string may not be in the same order you added them.chroot
- A chroot value for zookeeper, starting with a forward slash. If no
chroot is required, use null.httpClient
- the HttpClient
instance to be used for all requests. The provided httpClient should use a
multi-threaded connection manager. If null, a default HttpClient will be used.lbSolrClient
- LBHttpSolrClient instance for requests. If null, a default LBHttpSolrClient will be used.updatesToLeaders
- If true, sends updates to shard leaders.@Deprecated public CloudSolrClient(String zkHost, boolean updatesToLeaders)
CloudSolrClient.Builder
instead.zkHost
- A zookeeper client endpoint.updatesToLeaders
- If true, sends updates only to shard leaders.for full description and details on zkHost
@Deprecated public CloudSolrClient(String zkHost, boolean updatesToLeaders, org.apache.http.client.HttpClient httpClient)
CloudSolrClient.Builder
instead.zkHost
- A zookeeper client endpoint.updatesToLeaders
- If true, sends updates only to shard leaders.httpClient
- the HttpClient
instance to be used for all requests. The provided httpClient should use a
multi-threaded connection manager.for full description and details on zkHost
@Deprecated public CloudSolrClient(String zkHost, LBHttpSolrClient lbClient)
CloudSolrClient.Builder
instead.zkHost
- A zookeeper client endpoint.lbClient
- LBHttpSolrServer instance for requests.for full description and details on zkHost
@Deprecated public CloudSolrClient(String zkHost, LBHttpSolrClient lbClient, boolean updatesToLeaders)
CloudSolrClient.Builder
instead.zkHost
- A zookeeper client endpoint.lbClient
- LBHttpSolrServer instance for requests.updatesToLeaders
- If true, sends updates only to shard leaders.for full description and details on zkHost
public void setSoTimeout(int timeout)
public void setCollectionCacheTTl(int seconds)
seconds
- ttl value in secondspublic ResponseParser getParser()
public void setParser(ResponseParser processor)
processor
- Default Response Parser chosen to parse the response if the parser
were not specified as part of the request.SolrRequest.getResponseParser()
public RequestWriter getRequestWriter()
public void setRequestWriter(RequestWriter requestWriter)
public String getZkHost()
public ZkStateReader getZkStateReader()
public void setIdField(String idField)
idField
- the field to route documents on.public String getIdField()
public void setDefaultCollection(String collection)
public String getDefaultCollection()
public void setZkConnectTimeout(int zkConnectTimeout)
public void setZkClientTimeout(int zkClientTimeout)
public void connect()
public void connect(long duration, TimeUnit timeUnit) throws TimeoutException, InterruptedException
duration
- the timeouttimeUnit
- the units of the timeoutTimeoutException
- if the cluster is not ready after the timeoutInterruptedException
- if the wait is interruptedpublic void setParallelUpdates(boolean parallelUpdates)
public void uploadConfig(Path configPath, String configName) throws IOException
configPath
- Path
to the config filesconfigName
- the name of the configIOException
- if an IO error occurspublic void downloadConfig(String configName, Path downloadPath) throws IOException
configName
- the name of the configdownloadPath
- the path to write config files toIOException
- if an I/O exception occurspublic void waitForState(String collection, long wait, TimeUnit unit, CollectionStatePredicate predicate) throws InterruptedException, TimeoutException
collection
- the collection to watchwait
- how long to waitunit
- the units of the wait parameterpredicate
- a CollectionStatePredicate
to check the collection stateInterruptedException
- on interruptTimeoutException
- on timeoutpublic void registerCollectionStateWatcher(String collection, CollectionStateWatcher watcher)
CollectionStateWatcher.onStateChanged(Set, DocCollection)
callcollection
- the collection to watchwatcher
- a watcher that will be called when the state changespublic CloudSolrClient.RouteResponse condenseResponse(NamedList response, int timeMillis)
public NamedList<Object> request(SolrRequest request, String collection) throws SolrServerException, IOException
SolrClient
request
in class SolrClient
request
- the request to executecollection
- the collection to execute the request againstNamedList
containing the response from the serverSolrServerException
- if there is an error on the serverIOException
- If there is a low-level I/O error.protected NamedList<Object> requestWithRetryOnStaleState(SolrRequest request, int retryCount, String collection) throws SolrServerException, IOException
SolrServerException
IOException
protected NamedList<Object> sendRequest(SolrRequest request, String collection) throws SolrServerException, IOException
SolrServerException
IOException
public void close() throws IOException
IOException
public LBHttpSolrClient getLbClient()
public org.apache.http.client.HttpClient getHttpClient()
public boolean isUpdatesToLeaders()
public boolean isDirectUpdatesToLeadersOnly()
public void setParallelCacheRefreshes(int n)
protected DocCollection getDocCollection(ClusterState clusterState, String collection, Integer expectedVersion) throws SolrException
SolrException
public int getMinAchievedReplicationFactor(String collection, NamedList resp)
public Map<String,Integer> getShardReplicationFactor(String collection, NamedList resp)
Copyright © 2000-2016 Apache Software Foundation. All Rights Reserved.