Package org.apache.solr.client.solrj

# Class SolrRequest<T>

java.lang.Object
org.apache.solr.client.solrj.SolrRequest<T>

Type Parameters:
  `T` - the response type, that which is returned from a `process` method. For V1 APIs, it's a `SolrResponse`.

All Implemented Interfaces:
  `Serializable`

Direct Known Subclasses:
  `AliasesApi.CreateAlias`, `AliasesApi.DeleteAlias`, `AliasesApi.GetAliasByName`, `AliasesApi.GetAliases`, `AliasPropertiesApi.CreateOrUpdateAliasProperty`, `AliasPropertiesApi.DeleteAliasProperty`, `AliasPropertiesApi.GetAliasProperty`, `AliasPropertiesApi.GetAllAliasProperties`, `AliasPropertiesApi.UpdateAliasProperties`, `ClusterApi.BalanceReplicas`, `ClusterApi.MigrateReplicas`, `ClusterPropertiesApi.CreateOrUpdateClusterProperty`, `ClusterPropertiesApi.CreateOrUpdateNestedClusterProperty`, `ClusterPropertiesApi.DeleteClusterProperty`, `ClusterPropertiesApi.GetClusterProperty`, `ClusterPropertiesApi.ListClusterProperties`, `CollectionAdminRequest`, `CollectionBackupsApi.CreateCollectionBackup`, `CollectionBackupsApi.DeleteMultipleBackupsByRecency`, `CollectionBackupsApi.DeleteSingleBackupById`, `CollectionBackupsApi.GarbageCollectUnusedBackupFiles`, `CollectionBackupsApi.ListBackupsAtLocation`, `CollectionBackupsApi.RestoreCollection`, `CollectionPropertiesApi.CreateOrUpdateCollectionProperty`, `CollectionPropertiesApi.DeleteCollectionProperty`, `CollectionRequiringSolrRequest`, `CollectionsApi.BalanceShardUnique`, `CollectionsApi.CreateCollection`, `CollectionsApi.DeleteCollection`, `CollectionsApi.GetCollectionStatus`, `CollectionsApi.ListCollections`, `CollectionsApi.ReloadCollection`, `CollectionsApi.RenameCollection`, `CollectionSnapshotsApi.CreateCollectionSnapshot`, `CollectionSnapshotsApi.DeleteCollectionSnapshot`, `CollectionSnapshotsApi.ListSnapshots`, `ConfigSetAdminRequest`, `ConfigsetsApi.CloneExistingConfigSet`, `ConfigsetsApi.DeleteConfigSet`, `ConfigsetsApi.ListConfigSet`, `ConfigsetsApi.UploadConfigSet`, `ConfigsetsApi.UploadConfigSetFile`, `CoreAdminRequest`, `CoreBackupsApi.CreateBackup`, `CoresApi.CreateCore`, `CoresApi.GetAllCoreStatus`, `CoresApi.GetCoreStatus`, `CoresApi.InstallCoreData`, `CoresApi.MergeIndexes`, `CoresApi.ReloadCore`, `CoresApi.RenameCore`, `CoresApi.RestoreCore`, `CoresApi.SwapCores`, `CoresApi.UnloadCore`, `CoreSnapshotsApi.CreateSnapshot`, `CoreSnapshotsApi.DeleteSnapshot`, `CoreSnapshotsApi.ListSnapshots1`, `DelegationTokenRequest`, `FileStoreApi.DeleteFile`, `FileStoreApi.FetchFile`, `FileStoreApi.GetFile`, `FileStoreApi.GetMetadata`, `FileStoreApi.SyncFile`, `FileStoreApi.UploadFile`, `GenericSolrRequest`, `HealthCheckRequest`, `LoggingApi.FetchLocalLogMessages`, `LoggingApi.ListAllLoggersAndLevels`, `LoggingApi.ModifyLocalLogLevel`, `LoggingApi.SetMessageThreshold`, `NodeApi.DeleteNode`, `NodeApi.GetCommandStatus`, `NodeApi.GetPublicKey`, `NodeApi.ReplaceNode`, `QueryingApi.JsonQuery`, `QueryingApi.Query`, `ReplicaPropertiesApi.AddReplicaProperty`, `ReplicaPropertiesApi.DeleteReplicaProperty`, `ReplicasApi.CreateReplica`, `ReplicasApi.DeleteReplicaByName`, `ReplicasApi.DeleteReplicasByCount`, `ReplicasApi.DeleteReplicasByCountAllShards`, `ReplicationApi.FetchFile1`, `ReplicationApi.FetchFileList`, `ReplicationApi.FetchIndexVersion`, `ReplicationBackupsApi.CreateBackup1`, `SchemaApi.AddDynamicField`, `SchemaApi.AddField`, `SchemaApi.AddFieldType`, `SchemaApi.BulkSchemaModification`, `SchemaApi.DeleteDynamicField`, `SchemaApi.DeleteField`, `SchemaApi.DeleteFieldType`, `SchemaApi.GetDynamicFieldInfo`, `SchemaApi.GetFieldInfo`, `SchemaApi.GetFieldTypeInfo`, `SchemaApi.GetSchemaInfo`, `SchemaApi.GetSchemaName`, `SchemaApi.GetSchemaSimilarity`, `SchemaApi.GetSchemaUniqueKey`, `SchemaApi.GetSchemaVersion`, `SchemaApi.GetSchemaZkVersion`, `SchemaApi.ListCopyFields`, `SchemaApi.ListDynamicFields`, `SchemaApi.ListSchemaFields`, `SchemaApi.ListSchemaFieldTypes`, `SegmentsApi.GetSegmentData`, `ShardsApi.CreateShard`, `ShardsApi.DeleteShard`, `ShardsApi.ForceShardLeader`, `ShardsApi.InstallShardData`, `ShardsApi.SyncShard`, `V2Request`, `ZookeeperReadApi.ListNodes`, `ZookeeperReadApi.ReadNode`

public abstract class SolrRequest<T> extends Object implements Serializable
The SolrJ base class for a request into Solr. If you create one of these, then call `process(SolrClient)` to send it and get a typed response. There are some convenience methods on `SolrClient` that avoids the need to even create these explicitly for common cases.

Since:
  solr 1.3
See Also:
  - `QueryRequest`
  - `UpdateRequest`
  - Serialized Form

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`static enum`
`SolrRequest.ApiVersion`
`static enum`
`SolrRequest.METHOD`
`static enum`
`SolrRequest.SolrClientContext`
`static enum`
`SolrRequest.SolrRequestType`

## Field Summary

Fields
Modifier and Type
Field
Description
`static final Set<String>`
`SUPPORTED_METHODS`

## Constructor Summary

Constructors
Constructor
Description
`SolrRequest(SolrRequest.METHOD m, String path, SolrRequest.SolrRequestType requestType)`

## Method Summary

Modifier and Type
Method
Description
`void`
`addHeader(String key, String value)`
`void`
`addHeaders(Map<String,String> headers)`
`protected abstract T`
`createResponse(NamedList<Object> namedList)`
Create a new SolrResponse to hold the response from the server.
`SolrRequest.ApiVersion`
`getApiVersion()`
Indicates which API version this request will make
`String`
`getBasicAuthPassword()`
`String`
`getBasicAuthUser()`
`String`
`getCollection()`
`Collection<ContentStream>`
`getContentStreams()`
Deprecated.
Please use `getContentWriter(String)` instead.
`RequestWriter.ContentWriter`
`getContentWriter(String expectedType)`
If a request object wants to do a push write, implement this method.
`Map<String,String>`
`getHeaders()`
`SolrRequest.METHOD`
`getMethod()`
`abstract SolrParams`
`getParams()`
The parameters for this request; never null.
`String`
`getPath()`
`List<String>`
`getPreferredNodes()`
`Set<String>`
`getQueryParams()`
Parameter keys that are sent via the query string
`SolrRequest.SolrRequestType`
`getRequestType()`
The type of this Solr request.
`ResponseParser`
`getResponseParser()`
`StreamingResponseCallback`
`getStreamingResponseCallback()`
`Principal`
`getUserPrincipal()`
`final T`
`process(SolrClient client)`
Send this request to a `SolrClient` and return the response
`final T`
`process(SolrClient client, String collection)`
Send this request to a `SolrClient` and return the response
`final T`
`processWithBaseUrl(HttpSolrClientBase client, String baseUrl, String collection)`
Send this request to a `SolrClient` and return the response
`boolean`
`requiresCollection()`
Determines whether this request should use or ignore any specified collections (esp.
`SolrRequest<T>`
`setBasicAuthCredentials(String user, String password)`
`void`
`setMethod(SolrRequest.METHOD method)`
`void`
`setPath(String path)`
`SolrRequest<T>`
`setPreferredNodes(List<String> nodes)`
`void`
`setQueryParams(Set<String> queryParams)`
`void`
`setRequestType(SolrRequest.SolrRequestType requestType)`
`void`
`setResponseParser(ResponseParser responseParser)`
Optionally specify how the Response should be parsed.
`void`
`setStreamingResponseCallback(StreamingResponseCallback callback)`
`void`
`setUserPrincipal(Principal userPrincipal)`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### SUPPORTED_METHODS

public static final Set<String> SUPPORTED_METHODS

## Constructor Details

### SolrRequest

public SolrRequest(SolrRequest.METHOD m, String path, SolrRequest.SolrRequestType requestType)

## Method Details

### setUserPrincipal

public void setUserPrincipal(Principal userPrincipal)

### getUserPrincipal

public Principal getUserPrincipal()

### setPreferredNodes

public SolrRequest<T> setPreferredNodes(List<String> nodes)

### getPreferredNodes

public List<String> getPreferredNodes()

### setBasicAuthCredentials

public SolrRequest<T> setBasicAuthCredentials(String user, String password)

### getBasicAuthUser

public String getBasicAuthUser()

### getBasicAuthPassword

public String getBasicAuthPassword()

### getMethod

public SolrRequest.METHOD getMethod()

### setMethod

public void setMethod(SolrRequest.METHOD method)

### getPath

public String getPath()

### setPath

public void setPath(String path)

### getResponseParser

public ResponseParser getResponseParser()

Returns:
  The `ResponseParser`

### setResponseParser

public void setResponseParser(ResponseParser responseParser)
Optionally specify how the Response should be parsed. Not all server implementations require a ResponseParser to be specified.

Parameters:
  `responseParser` - The `ResponseParser`

### getStreamingResponseCallback

public StreamingResponseCallback getStreamingResponseCallback()

### setStreamingResponseCallback

public void setStreamingResponseCallback(StreamingResponseCallback callback)

### getQueryParams

public Set<String> getQueryParams()
Parameter keys that are sent via the query string

### setQueryParams

public void setQueryParams(Set<String> queryParams)

### getRequestType

public SolrRequest.SolrRequestType getRequestType()
The type of this Solr request.

Pattern matches `getPath()` to identify ADMIN requests and other special cases. Overriding this method may affect request routing within various clients (i.e. `CloudSolrClient`).

### setRequestType

public void setRequestType(SolrRequest.SolrRequestType requestType)

### getParams

public abstract SolrParams getParams()
The parameters for this request; never null. The runtime type may be mutable but modifications may not affect this `SolrRequest` instance, as it may return a new instance here every time. If the subclass specifies the response type as `ModifiableSolrParams`, then one can expect it to change this request. If the subclass has a setter then one can expect this method to return the value set.

### requiresCollection

public boolean requiresCollection()
Determines whether this request should use or ignore any specified collections (esp. `SolrClient.defaultCollection`)

Many Solr requests target a particular core or collection. But not all of them - many Solr APIs (e.g. security or other admin APIs) are agnostic of collections entirely. This method gives these requests a way to opt out of using `SolrClient.defaultCollection` or other specified collections.

### getApiVersion

public SolrRequest.ApiVersion getApiVersion()
Indicates which API version this request will make

Defaults implementation returns 'V1'.

### getContentStreams

@Deprecated public Collection<ContentStream> getContentStreams() throws IOException
Deprecated.
Please use `getContentWriter(String)` instead.

Throws:
  `IOException`

### getContentWriter

public RequestWriter.ContentWriter getContentWriter(String expectedType)
If a request object wants to do a push write, implement this method.

Parameters:
  `expectedType` - This is the type that the RequestWriter would like to get. But, it is OK to send any format

### createResponse

protected abstract T createResponse(NamedList<Object> namedList)
Create a new SolrResponse to hold the response from the server. If the response extends `SolrResponse`, then there's no need to use the arguments, as `SolrResponse.setResponse(NamedList)` will be called right after this method.

Parameters:
  `namedList` - from `SolrClient.request(SolrRequest, String)`.

### process

public final T process(SolrClient client, String collection) throws SolrServerException, IOException
Send this request to a `SolrClient` and return the response

Parameters:
  `client` - the SolrClient to communicate with
  `collection` - the collection to execute the request against
Returns:
  the response
Throws:
  `SolrServerException` - if there is an error on the Solr server
  `IOException` - if there is a communication error

### processWithBaseUrl

public final T processWithBaseUrl(HttpSolrClientBase client, String baseUrl, String collection) throws SolrServerException, IOException
Send this request to a `SolrClient` and return the response

Parameters:
  `client` - the SolrClient to communicate with
  `baseUrl` - the base URL, e.g. `Http://localhost:8983/solr`
  `collection` - the collection to execute the request against
Returns:
  the response
Throws:
  `SolrServerException` - if there is an error on the Solr server
  `IOException` - if there is a communication error
WARNING: This API is experimental and might change in incompatible ways in the next release.

### process

public final T process(SolrClient client) throws SolrServerException, IOException
Send this request to a `SolrClient` and return the response

Parameters:
  `client` - the SolrClient to communicate with
Returns:
  the response
Throws:
  `SolrServerException` - if there is an error on the Solr server
  `IOException` - if there is a communication error

### getCollection

public String getCollection()

### addHeader

public void addHeader(String key, String value)

### addHeaders

public void addHeaders(Map<String,String> headers)

### getHeaders

public Map<String,String> getHeaders()