Apache Solr Documentation

6.5 Ref Guide (PDF Download)
Solr Tutorial
Solr Community Wiki

Older Versions of this Guide (PDF)

Ref Guide Topics

Meta-Documentation

*** As of June 2017, the latest Solr Ref Guide is located at https://lucene.apache.org/solr/guide ***

Please note comments on these pages have now been disabled for all users.

Skip to end of metadata
Go to start of metadata

The Config API enables manipulating various aspects of your solrconfig.xml using REST-like API calls. This feature is enabled by default and works similarly in both SolrCloud and standalone mode. Many commonly edited properties (such as cache sizes and commit settings) and request handler definitions can be changed with this API.

When using this API, solrconfig.xml is not changed. Instead, all edited configuration is stored in a file called configoverlay.json. The values in configoverlay.json override the values in solrconfig.xml.

API Entry Points

  • /config: retrieve or modify the config. GET to retrieve and POST for executing commands
  • /config/overlay: retrieve the details in the configoverlay.json alone
  • /config/params : allows creating parameter sets that can override or take the place of parameters defined in solrconfig.xml. See the Request Parameters API section for more details.

Retrieving the config

All configuration items, can be retrieved by sending a GET request to the /config endpoint - the results will be the effective configuration resulting from merging settings in configoverlay.json with those in solrconfig.xml:

To restrict the returned results to a top level section, e.g. query, requestHandler or updateHandler, append the name of the section to the /config endpoint following a slash. E.g. to retrieve configuration for all request handlers:

To further restrict returned results to a single component within a top level section, use the componentName request param, e.g. to return configuration for the /select request handler:

Commands to modify the config

This API uses specific commands to tell Solr what property or type of property to add to configoverlay.json. The commands are passed as part of the data sent with the request.

The config commands are categorized into 3 different sections which manipulate various data structures in solrconfig.xml. Each of these is described below.

Commands for Common Properties

The common properties are those that are frequently need to be customized in a Solr instance. They are manipulated with two commands: 

  • set-property: Set a well known property. The names of the properties are predefined and fixed. If the property has already been set, this command will overwrite the previous setting.
  • unset-property: Remove a property set using the set-property command.

The properties that are configured with these commands are predefined and listed below. The names of these properties are derived from their XML paths as found in solrconfig.xml.

 

  • updateHandler.autoCommit.maxDocs
  • updateHandler.autoCommit.maxTime
  • updateHandler.autoCommit.openSearcher
  • updateHandler.autoSoftCommit.maxDocs
  • updateHandler.autoSoftCommit.maxTime
  • updateHandler.commitWithin.softCommit
  • updateHandler.indexWriter.closeWaitsForMerges
  • query.filterCache.class
  • query.filterCache.size
  • query.filterCache.initialSize
  • query.filterCache.autowarmCount
  • query.filterCache.regenerator
  • query.queryResultCache.class
  • query.queryResultCache.size
  • query.queryResultCache.initialSize
  • query.queryResultCache.autowarmCount
  • query.queryResultCache.regenerator
  • query.documentCache.class
  • query.documentCache.size
  • query.documentCache.initialSize
  • query.documentCache.autowarmCount
  • query.documentCache.regenerator
  • query.fieldValueCache.class
  • query.fieldValueCache.size
  • query.fieldValueCache.initialSize
  • query.fieldValueCache.autowarmCount
  • query.fieldValueCache.regenerator
  • query.useFilterForSortedQuery
  • query.queryResultWindowSize
  • query.queryResultMaxDocCached
  • query.enableLazyFieldLoading
  • query.boolToFilterOptimizer
  • query.maxBooleanClauses
  • jmx.agentId
  • jmx.serviceUrl
  • jmx.rootName
  • requestDispatcher.handleSelect
  • requestDispatcher.requestParsers.multipartUploadLimitInKB
  • requestDispatcher.requestParsers.formdataUploadLimitInKB
  • requestDispatcher.requestParsers.enableRemoteStreaming
  • requestDispatcher.requestParsers.addHttpRequestToContext

Commands for Custom Handlers and Local Components

Custom request handlers, search components, and other types of localized Solr components (such as custom query parsers, update processors, etc.) can be added, updated and deleted with specific commands for the component being modified.

The syntax is similar in each case: add-<component-name>, update-<component-name>, and delete-<component-name>. Please note that the command name is not case sensitive, so  Add-RequestHandler, ADD-REQUESTHANDLER and add-requesthandler are all equivalent. In each case, add-commands add the new configuration to configoverlay.json, which will override any other settings for the component in solrconfig.xml; update- commands overwrite an existing setting in configoverlay.json; and delete- commands remove the setting from configoverlay.json. Settings removed from configoverlay.json are not removed from solrconfig.xml.

The full list of available commands follows below:

General Purpose Commands

These commands are the most commonly used:

  • add-requesthandler
  • update-requesthandler
  • delete-requesthandler
  • add-searchcomponent
  • update-searchcomponent
  • delete-searchcomponent
  • add-initparams
  • update-initparams
  • delete-initparams
  • add-queryresponsewriter
  • update-queryresponsewriter
  • delete-queryresponsewriter

Advanced Commands

These commands allow registering more advanced customizations to Solr:

  • add-queryparser
  • update-queryparser
  • delete-queryparser
  • add-valuesourceparser
  • update-valuesourceparser
  • delete-valuesourceparser
  • add-transformer
  • update-transformer
  • delete-transformer
  • add-updateprocessor
  • update-updateprocessor
  • delete-updateprocessor
  • add-queryconverter
  • update-queryconverter
  • delete-queryconverter
  • add-listener
  • update-listener
  • delete-listener
  • add-runtimelib
  • update-runtimelib
  • delete-runtimelib

See the section Creating and Updating Request Handlers below for examples of using these commands.

What about <updateRequestProcessorChain>?

The Config API does not let you create or edit <updateRequestProcessorChain> elements. However, it is possible to create <updateProcessor> entries and can use them by name to create a chain.

example:

You can use this directly in your request by adding a parameter in the <updateRequestProcessorChain> for the specific update processor called processor=firstFld.

Commands for User-Defined Properties

Solr lets users templatize the solrconfig.xml using the place holder format ${variable_name:default_val}. You could set the values using system properties, for example, -Dvariable_name= my_customvalue. The same can be achieved during runtime using these commands:

  • set-user-property: Set a user-defined property. If the property has already been set, this command will overwrite the previous setting.
  • unset-user-property:  Remove a user-defined property.

The structure of the request is similar to the structure of requests using other commands, in the format of "command":{"variable_name":"property_value"}. You can add more than one variable at a time if necessary.

For more information about user-defined properties, see the section User defined properties from core.properties. See also the section Creating and Updating User-Defined Properties below for examples of how to use this type of command.

How to Map solrconfig.xml Properties to JSON

By using this API, you will be generating JSON representations of properties defined in solrconfig.xml. To understand how properties should be represented with the API, let's take a look at a few examples.

Here is what a request handler looks like in solrconfig.xml:

The same request handler defined with the Config API would look like this:

The QueryElevationComponent searchComponent in solrconfig.xml looks like this:

And the same searchComponent with the Config API:

Removing the searchComponent with the Config API:

 

A simple highlighter looks like this in solrconfig.xml (example has been truncated for space):

The same highlighter with the Config API:

Set autoCommit properties in solrconfig.xml:

Define the same properties with the Config API:

Name Components for the Config API

The Config API always allows changing the configuration of any component by name. However, some configurations such as listener or initParams do not require a name in solrconfig.xml. In order to be able to update and delete of the same item in configoverlay.json, the name attribute becomes mandatory.

Examples

Creating and Updating Common Properties 

This change sets the query.filterCache.autowarmCountto 1000 items and unsets the query.filterCache.size.

Using the /config/overlay endpoint, you can verify the changes with a request like this:

And you should get a response like this:

Creating and Updating Request Handlers

To create a request handler, we can use the add-requesthandler command:

Make a call to the new request handler to check if it is registered:

And you should see the following as output:


To update a request handler, you should use the update-requesthandler command :


As another example, we'll create another request handler, this time adding the 'terms' component as part of the definition:

Creating and Updating User-Defined Properties

This command sets a user property. 

Again, we can use the /config/overlay endpoint to verify the changes have been made:

And we would expect to see output like this:

To unset the variable, issue a command like this:

How It Works

Every core watches the ZooKeeper directory for the configset being used with that core. In standalone mode, however, there is no watch (because ZooKeeper is not running). If there are multiple cores in the same node using the same configset, only one ZooKeeper watch is used. For instance, if the configset 'myconf' is used by a core, the node would watch /configs/myconf. Every write operation performed through the API would 'touch' the directory (sets an empty byte[] to trigger watches) and all watchers are notified. Every core would check if the Schema file, solrconfig.xml or configoverlay.json is modified by comparing the znode versions and if modified, the core is reloaded.

If params.json is modified, the params object is just updated without a core reload (see the section Request Parameters API for more information about params.json).

Empty Command 

If an empty command is sent to the /config endpoint, the watch is triggered on all cores using this configset. For example:

Directly editing any files without 'touching' the directory will not make it visible to all nodes.

It is possible for components to watch for the configset 'touch' events by registering a listener using SolrCore#registerConfListener() .

Listening to config Changes

Any component can register a listener using:

SolrCore#addConfListener(Runnable listener)

to get notified for config changes. This is not very useful if the files modified result in core reloads (i.e., configoverlay.xml or Schema).  Components can use this to reload the files they are interested in. 

 

  • No labels

4 Comments

  1. The add-requesthandler example has an extra comma at the end that stops it working.  It should be:-

    curl http://localhost:8983/solr/techproducts/config -H 'Content-type:application/json'  -d '{
      "add-requesthandler" : {
        "name""/mypath",
        "class":"solr.DumpRequestHandler",
        "defaults":{ "x":"y" ,"a":"b""wt":"json""indent":true },
        "useParams":"x"
      }
    }'

    Feel free to delete this comment once this is fixed.  Great documentation BTW (smile)

    1. Hi Steve,

       

      Thanks for reporting. It's fixed now.

      1. Varun Thacker, it looks like your edit added an extra phrase at the start of the first paragraph ("add-requesthandler"). This was a complete mistake right? Meaning, you didn't intend to put that somewhere else, and it's OK for me to simply delete that phrase?