The UpdateRequestProcessor is configured in solrconfig.xml. All parameters listed may also be overridden on the update request itself. A minimal configuration specifies the script file to use:
NOTE: The processor supports the
defaults/appends/invariants concept for its config. However, it is also possible to skip this level and configure the parameters directly underneath the
Below follows a list of each configuration parameters and their meaning:
The script file name. The script file must be placed in the conf/ directory. There can be one or more "script" parameters specified; multiple scripts are executed in the order specified.
Optional parameters that are passed into the script execution context. This is specified as a named list (<lst>) structure with nested typed parameters. If specified, the script context will get a "params" object, otherwise there will be no "params" object available.
Script execution context
Logger (org.slf4j.Logger) instance. This is useful for logging information from the script.
SolrQueryRequest (org.apache.solr.request.SolrQueryRequest) instance.
SolrQueryResponse (org.apache.solr.response.SolrQueryResponse) instance.
The "params" object, if any specified, from the configuration.
The processAdd() and the other script methods can return false to skip further processing of the document. All methods must be defined, though generally the processAdd() method is where the action is.
Here's a URL that works with the collection1 example demonstrating specifying the "script" update chain: http://localhost:8983/solr/collection1/update?commit=true&stream.contentType=text/csv&fieldnames=id,description&stream.body=1,foo&update.chain=script which logs the following:
To use JRuby as the scripting engine, add jruby.jar to your system (in a lib/ directory under a collection, or via <lib> directives in solrconfig.xml).
Here's an example JRuby update processing script (note that all variables passed require prefixing with $, such as $logger):
Put all JARs from a Groovy distro's lib/ directory into Solr's resource loader (core lib/ directory, <lib> directive in solrconfig, etc). All JARs from Groovy's distro probably aren't required, but more than just the main Groovy .jar file is needed (at least when this was tested using Groovy 2.0.6)
Put the *standalone* jython JAR (the JAR that contains all the dependencies) into Solr's resource loader (core lib/ directory, <lib> directive in solrconfig, etc).
TBD: Add more on the "stateless" nature, running multiple scripts that can share state, and more about other scripting languages available.
- SOLR-1725: original JIRA issue tracking the initial development of this feature.