Configsets API
The Configsets API enables you to upload new configsets to ZooKeeper, create, and delete configsets when Solr is running SolrCloud mode.
Configsets are a collection of configuration files such as solrconfig.xml
, synonyms.txt
, the schema, language-specific files, and other collection-level configuration files (everything that normally lives in the conf
directory).
Solr ships with two example configsets (_default
and sample_techproducts_configs
) which can be used when creating collections.
Using the same concept, you can create your own configsets and make them available when creating collections.
This API provides a way to upload configuration files to ZooKeeper and share the same set of configuration files between two or more collections.
Once a configset has been uploaded to ZooKeeper, use the configset name when creating the collection with the Collections API and the collection will use your configuration files.
Configsets do not have to be shared between collections if they are uploaded with this API, but this API makes it easier to do so if you wish.
An alternative to uploading your configsets in advance would be to put the configuration files into a directory under server/solr/configsets
and using the directory name as the -d
parameter when using bin/solr create
to create a collection.
This API can only be used with Solr running in SolrCloud mode. If you are not running Solr in SolrCloud mode but would still like to use shared configurations, please see the section Configsets. |
The API works by passing commands to the configs
endpoint.
The path to the endpoint varies depending on the API being used: the v1 API uses solr/admin/configs
, while the v2 API uses api/cluster/configs
.
Examples of both types are provided below.
List Configsets
The list
command fetches the names of the configsets that are available for use during collection creation.
V1 API
With the v1 API, the list
command must be capitalized as LIST
:
http://localhost:8983/solr/admin/configs?action=LIST&omitHeader=true
V2 API
With the v2 API, the list
command is implied when there is no data sent with the request.
http://localhost:8983/api/cluster/configs?omitHeader=true
The output will look like:
{
"configSets": [
"_default",
"techproducts",
"gettingstarted"
]
}
Upload a Configset
Upload a configset, which is sent as a zipped file.
A single, non-zipped file can also be uploaded with the filePath
parameter.
This functionality is enabled by default, but can be disabled via a runtime parameter -Dconfigset.upload.enabled=false
.
Disabling this feature is advisable if you want to expose Solr installation to untrusted users (even though you should never do that!).
A configset is uploaded in a "trusted" mode if authentication is enabled and the upload operation is performed as an authenticated request. Without authentication, a configset is uploaded in an "untrusted" mode. Upon creation of a collection using an "untrusted" configset, the following functionality will not work:
-
The XSLT transformer (
tr
parameter) cannot be used at request processing time. -
If specified in the configset, the ScriptUpdateProcessorFactory will not initialize.
-
Collections won’t initialize if <lib> directives are used in the configset. (Note: Libraries added to Solr’s classpath don’t need the <lib> directive)
If you use any of these parameters or features, you must have enabled security features in your Solr installation and you must upload the configset as an authenticated user.
The upload
command takes the following parameters:
name
-
Required
Default: none
The configset to be created when the upload is complete.
overwrite
-
Optional
Default: see description
If set to
true
, Solr will overwrite an existing configset with the same name (if false, the request will fail). IffilePath
is provided, then this option specifies whether the specified file within the configset should be overwritten if it already exists. Default isfalse
when using the v1 API, buttrue
when using the v2 API. cleanup
-
Optional
Default:
false
When overwriting an existing configset (
overwrite=true
), this parameter tells Solr to delete the files in ZooKeeper that existed in the old configset but not in the one being uploaded. This parameter cannot be set to true whenfilePath
is used. filePath
-
Optional
Default: none
This parameter allows the uploading of a single, non-zipped file to the given path under the configset in ZooKeeper. This functionality respects the
overwrite
parameter, so a request will fail if the given file path already exists in the configset and overwrite is set tofalse
. Thecleanup
parameter cannot be set to true whenfilePath
is used.
If uploading an entire configset, the body of the request should be a zip file that contains the configset.
The zip file must be created from within the conf
directory (i.e., solrconfig.xml
must be the top level entry in the zip file).
Here is an example on how to create the zip file named "myconfig.zip" and upload it as a configset named "myConfigSet":
V1 API
With the v1 API, the upload
command must be capitalized as UPLOAD
:
$ (cd solr/server/solr/configsets/sample_techproducts_configs/conf && zip -r - *) > myconfigset.zip
$ curl -X POST --header "Content-Type:application/octet-stream" --data-binary @myconfigset.zip "http://localhost:8983/solr/admin/configs?action=UPLOAD&name=myConfigSet"
The same can be achieved using a Unix pipe with a single request as follows:
$ (cd server/solr/configsets/sample_techproducts_configs/conf && zip -r - *) | curl -X POST --header "Content-Type:application/octet-stream" --data-binary @- "http://localhost:8983/solr/admin/configs?action=UPLOAD&name=myConfigSet"
V2 API
With the v2 API, the name of the configset to upload is provided as a path parameter:
$ (cd solr/server/solr/configsets/sample_techproducts_configs/conf && zip -r - *) > myconfigset.zip
$ curl -X PUT --header "Content-Type:application/octet-stream" --data-binary @myconfigset.zip
"http://localhost:8983/api/cluster/configs/myConfigSet"
With this API, the default behavior is to overwrite the configset if it already exists.
This behavior can be disabled with the parameter overwrite=false
, in which case the request will fail if the configset already exists.
Here is an example on how to upload a single file to a configset named "myConfigSet":
V1 API
With the v1 API, the upload
command must be capitalized as UPLOAD
.
The filename to upload is provided via the filePath
parameter:
curl -X POST --header "Content-Type:application/octet-stream"
--data-binary @solr/server/solr/configsets/sample_techproducts_configs/conf/solrconfig.xml
"http://localhost:8983/solr/admin/configs?action=UPLOAD&name=myConfigSet&filePath=solrconfig.xml&overwrite=true"
V2 API
With the v2 API, the name of the configset and file are both provided in the URL.
They can be substituted in /cluster/configs/config_name/file_name
.
The filename may be nested and include /
characters.
curl -X PUT --header "Content-Type:application/octet-stream"
--data-binary @solr/server/solr/configsets/sample_techproducts_configs/conf/solrconfig.xml
"http://localhost:8983/api/cluster/configs/myConfigSet/solrconfig.xml"
With this API, the default behavior is to overwrite the file if it already exists within the configset.
This behavior can be disabled with the parameter overwrite=false
, in which case the request will fail if the file already exists within the configset.
Create a Configset
The create
command creates a new configset based on a configset that has been previously uploaded.
If you have not yet uploaded any configsets, see the Upload a Configset command above.
The following parameters are supported when creating a configset.
name
-
Required
Default: none
The configset to be created.
baseConfigSet
-
Optional
Default:
_default
The name of the configset to copy as a base.
configSetProp.property=value
-
Optional
Default: none
A configset property from the base configset to override in the copied configset.
For example, to create a configset named "myConfigset" based on a previously defined "predefinedTemplate" configset, overriding the immutable property to false.
V1 API
With the v1 API, the create
command must be capitalized as CREATE
:
http://localhost:8983/solr/admin/configs?action=CREATE&name=myConfigSet&baseConfigSet=predefinedTemplate&configSetProp.immutable=false&wt=xml&omitHeader=true
V2 API
With the v2 API, the create
command is provided as part of the JSON data that contains the required parameters:
curl -X POST -H 'Content-type: application/json' -d '{
"create":{
"name": "myConfigSet",
"baseConfigSet": "predefinedTemplate",
"configSetProp.immutable": "false"}}'
http://localhost:8983/api/cluster/configs?omitHeader=true
With the v2 API, configset properties can also be provided via the properties
map:
curl -X POST -H 'Content-type: application/json' -d '{
"create":{
"name": "myConfigSet",
"baseConfigSet": "predefinedTemplate",
"properties": {
"immutable": "false"
}}}'
http://localhost:8983/api/cluster/configs?omitHeader=true
Output
<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">323</int>
</lst>
</response>
Delete a Configset
The delete
command removes a configset.
It does not remove any collections that were created with the configset.
name
-
Required
Default: none
The configset to be deleted.
To delete a configset named "myConfigSet":
V1 API
With the v1 API, the delete
command must be capitalized as DELETE
.
The name of the configset to delete is provided with the name
parameter:
http://localhost:8983/solr/admin/configs?action=DELETE&name=myConfigSet&omitHeader=true
V2 API
With the v2 API, the delete
command is provided as the request method, as in -X DELETE
.
The name of the configset to delete is provided as a path parameter:
curl -X DELETE http://localhost:8983/api/cluster/configs/myConfigSet?omitHeader=true
Output
<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">170</int>
</lst>
</response>