public class HttpSolrClient extends SolrClient
Modifier and Type | Class and Description |
---|---|
static class |
HttpSolrClient.Builder
Constructs
HttpSolrClient instances from provided configuration. |
static class |
HttpSolrClient.HttpUriRequestResponse |
static class |
HttpSolrClient.RemoteExecutionException
This should be thrown when a server has an error in executing the request and
it sends a proper payload back to the client
|
static class |
HttpSolrClient.RemoteSolrException
Subclass of SolrException that allows us to capture an arbitrary HTTP
status code that may have been returned by the remote server or a
proxy along the way.
|
Modifier and Type | Field and Description |
---|---|
static String |
AGENT
User-Agent String.
|
protected String |
baseUrl
The URL of the Solr server.
|
protected ModifiableSolrParams |
invariantParams
Default value: null / empty.
|
protected ResponseParser |
parser
Default response parser is BinaryResponseParser
|
protected RequestWriter |
requestWriter
The RequestWriter used to write all requests to Solr
|
Modifier | Constructor and Description |
---|---|
protected |
HttpSolrClient(HttpSolrClient.Builder builder) |
protected |
HttpSolrClient(String baseURL,
org.apache.http.client.HttpClient client,
ResponseParser parser,
boolean allowCompression)
Deprecated.
use
HttpSolrClient(Builder) instead, as it is a more extension/subclassing-friendly alternative |
protected |
HttpSolrClient(String baseURL,
org.apache.http.client.HttpClient client,
ResponseParser parser,
boolean allowCompression,
ModifiableSolrParams invariantParams)
Deprecated.
use
HttpSolrClient(Builder) instead, as it is a more extension/subclassing-friendly alternative |
Modifier and Type | Method and Description |
---|---|
protected ModifiableSolrParams |
calculateQueryParams(Set<String> queryParamNames,
ModifiableSolrParams wparams) |
void |
close()
Close the
HttpClientConnectionManager from the internal client. |
protected org.apache.http.client.methods.HttpRequestBase |
createMethod(SolrRequest request,
String collection) |
protected NamedList<Object> |
executeMethod(org.apache.http.client.methods.HttpRequestBase method,
ResponseParser processor,
boolean isV2Api) |
String |
getBaseURL() |
org.apache.http.client.HttpClient |
getHttpClient()
Return the HttpClient this instance uses.
|
ModifiableSolrParams |
getInvariantParams()
Retrieve the default list of parameters are added to every request
regardless.
|
ResponseParser |
getParser() |
Set<String> |
getQueryParams() |
HttpSolrClient.HttpUriRequestResponse |
httpUriRequest(SolrRequest request) |
HttpSolrClient.HttpUriRequestResponse |
httpUriRequest(SolrRequest request,
ResponseParser processor) |
boolean |
isUseMultiPartPost() |
NamedList<Object> |
request(SolrRequest request,
ResponseParser processor) |
NamedList<Object> |
request(SolrRequest request,
ResponseParser processor,
String collection) |
NamedList<Object> |
request(SolrRequest request,
String collection)
Process the request.
|
void |
setBaseURL(String baseURL)
Change the base-url used when sending requests to Solr.
|
void |
setConnectionTimeout(int timeout)
Deprecated.
since 7.0 Use
HttpSolrClient.Builder methods instead. |
void |
setFollowRedirects(boolean followRedirects)
Configure whether the client should follow redirects or not.
|
void |
setParser(ResponseParser processor)
Note: This setter method is not thread-safe.
|
void |
setQueryParams(Set<String> queryParams)
Expert Method
|
void |
setRequestWriter(RequestWriter requestWriter) |
void |
setSoTimeout(int timeout)
Deprecated.
|
void |
setUseMultiPartPost(boolean useMultiPartPost)
Set the multipart connection properties
|
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 AGENT
protected volatile String baseUrl
protected ModifiableSolrParams invariantParams
Parameters that are added to every request regardless. This may be a place to add something like an authentication token.
protected volatile ResponseParser parser
This parser represents the default Response Parser chosen to parse the response if the parser were not specified as part of the request.
BinaryResponseParser
protected volatile RequestWriter requestWriter
RequestWriter
@Deprecated protected HttpSolrClient(String baseURL, org.apache.http.client.HttpClient client, ResponseParser parser, boolean allowCompression)
HttpSolrClient(Builder)
instead, as it is a more extension/subclassing-friendly alternative@Deprecated protected HttpSolrClient(String baseURL, org.apache.http.client.HttpClient client, ResponseParser parser, boolean allowCompression, ModifiableSolrParams invariantParams)
HttpSolrClient(Builder)
instead, as it is a more extension/subclassing-friendly alternativebaseURL
- The base url to communicate with the Solr serverclient
- Http client instance to use for communicationparser
- Response parser instance to use to decode response from Solr serverallowCompression
- Should compression be allowed ?invariantParams
- The parameters which should be included with every request.protected HttpSolrClient(HttpSolrClient.Builder builder)
public void setQueryParams(Set<String> queryParams)
queryParams
- set of param keys to only send via the query string
Note that the param will be sent as a query string if the key is part
of this Set or the SolrRequest's query params.SolrRequest.getQueryParams()
public NamedList<Object> request(SolrRequest request, String collection) throws SolrServerException, IOException
SolrRequest.getResponseParser()
is
null, then use getParser()
request
in class SolrClient
request
- The SolrRequest
to processcollection
- the collection to execute the request againstNamedList
resultIOException
- If there is a low-level I/O error.SolrServerException
- if there is an error on the serverrequest(org.apache.solr.client.solrj.SolrRequest,
org.apache.solr.client.solrj.ResponseParser)
public NamedList<Object> request(SolrRequest request, ResponseParser processor) throws SolrServerException, IOException
SolrServerException
IOException
public NamedList<Object> request(SolrRequest request, ResponseParser processor, String collection) throws SolrServerException, IOException
SolrServerException
IOException
public HttpSolrClient.HttpUriRequestResponse httpUriRequest(SolrRequest request) throws SolrServerException, IOException
SolrServerException
IOException
public HttpSolrClient.HttpUriRequestResponse httpUriRequest(SolrRequest request, ResponseParser processor) throws SolrServerException, IOException
SolrServerException
IOException
protected ModifiableSolrParams calculateQueryParams(Set<String> queryParamNames, ModifiableSolrParams wparams)
protected org.apache.http.client.methods.HttpRequestBase createMethod(SolrRequest request, String collection) throws IOException, SolrServerException
IOException
SolrServerException
protected NamedList<Object> executeMethod(org.apache.http.client.methods.HttpRequestBase method, ResponseParser processor, boolean isV2Api) throws SolrServerException
SolrServerException
public ModifiableSolrParams getInvariantParams()
invariantParams
public String getBaseURL()
public void setBaseURL(String baseURL)
httpSolrClient.setBaseURL("http://my-solr-server:8983/solr/core1"); QueryResponse resp = httpSolrClient.query(new SolrQuery("*:*"));Note that when a core is provided in the base URL, queries and other requests can be made without mentioning the core explicitly. However, the client can only send requests to that core. 2) The path of the root Solr path ("/solr")
httpSolrClient.setBaseURL("http://my-solr-server:8983/solr"); QueryResponse resp = httpSolrClient.query("core1", new SolrQuery("*:*"));In this case the client is more flexible and can be used to send requests to any cores. The cost of this is that the core must be specified on each request.
public 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 org.apache.http.client.HttpClient getHttpClient()
@Deprecated public void setConnectionTimeout(int timeout)
HttpSolrClient.Builder
methods instead.timeout
- Timeout in milliseconds@Deprecated public void setSoTimeout(int timeout)
timeout
- Timeout in milliseconds
s * @deprecated since 7.0 Use HttpSolrClient.Builder
methods instead.public void setFollowRedirects(boolean followRedirects)
This defaults to false under the assumption that if you are following a redirect to get to a Solr installation, something is misconfigured somewhere.
public void setRequestWriter(RequestWriter requestWriter)
public void close() throws IOException
HttpClientConnectionManager
from the internal client.IOException
public boolean isUseMultiPartPost()
public void setUseMultiPartPost(boolean useMultiPartPost)
Copyright © 2000-2017 Apache Software Foundation. All Rights Reserved.