Differences between revisions 15 and 16
Revision 15 as of 2012-10-16 01:59:59
Size: 5138
Editor: pool-173-61-96-238
Revision 16 as of 2013-08-20 17:39:17
Size: 5378
Editor: HossMan
Comment: note about default="true"
Deletions are marked like this. Additions are marked like this.
Line 12: Line 12:
 <updateRequestProcessorChain name="mychain" >  <updateRequestProcessorChain name="mychain" default="true">
Line 25: Line 25:

At most one processor may be configured as the "default". if no processor is configured as a default, then an implicit default useing {{{LogUpdateProcessorFactory}}} and {{{RunUpdateProcessorFactory}}} is created for you.

/!\ Solr1.3

UpdateRequestProcessors can be mixed and matched in UpdateRequestProcessorChains that define how update requests are processed.

Configuring Update Request Processors

solrconfig.xml files can contain any number of UpdateRequestProcessorChains...

 <updateRequestProcessorChain name="mychain" default="true">
   <processor class="solr.CustomUpdateRequestProcessorFactory" >
     <lst name="name">
       <str name="n1">x1</str>
       <str name="n2">x2</str>
   <processor class="solr.LogUpdateProcessorFactory" />
   <processor class="solr.RunUpdateProcessorFactory" />

Allmost all processor chains should end with an instance of RunUpdateProcessorFactory unless the user is explicitly executing the update commands in an alternative custom !UpdateRequestProcessorFactory.

At most one processor may be configured as the "default". if no processor is configured as a default, then an implicit default useing LogUpdateProcessorFactory and RunUpdateProcessorFactory is created for you.

Selecting the UpdateChain for Your Request

Once one or more update chains are defined, you may select one on the update request through the parameter update.chain

Example: http://localhost:8983/solr/update/xml?update.chain=mychain.

<!> Note: for Solr versions prior to Solr3.2 you need to use update.processor instead <!>

You may also choose to set a default chain for a certain UpdateRequestHandler:

 <!-- referencing it in an update handler -->
 <requestHandler name="/update/processortest" class="solr.JsonUpdateRequestHandler" >
   <lst name="defaults">
     <str name="update.chain">mychain</str>

Distributed Updates

Begining with Solr4.0 all UpdateRequestProcessorChains which include RunUpdateProcessorFactory, but do not include an implementation of the DistributingUpdateProcessorFactory will have an instance of DistributedUpdateProcessorFactory automaticly injected immediately prior to the RunUpdateProcessorFactory.

In single-server instances, DistributedUpdateProcessorFactory is a No-Op, but for Solr Cloud instances, it determines where the in the chain the request gets forwarded to the leader (and other all other nodes in the shard). Processors prior to DistributedUpdateProcessorFactory in the chain will be executed only on the first node to recieve the command, processors after the DistributedUpdateProcessorFactory will be executed on every node in the appropriate shard(s).

Processor Customization Examples

Field Mutating Update Processors

Beginging with Solr4.0 various FieldMutatingUpdateProcessorFactories are available that can be mixed and matched to accomplish a variety of goals.

Implementing a conditional copyField

Here is a quick example that adds the 'cat' 'popular' if the value of 'popularity' is > 5

package my.solr;

import java.io.IOException;

import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.update.AddUpdateCommand;
import org.apache.solr.update.processor.UpdateRequestProcessor;
import org.apache.solr.update.processor.UpdateRequestProcessorFactory;

public class ConditionalCopyProcessorFactory extends UpdateRequestProcessorFactory
  public UpdateRequestProcessor getInstance(SolrQueryRequest req, SolrQueryResponse rsp, UpdateRequestProcessor next)
    return new ConditionalCopyProcessor(next);

class ConditionalCopyProcessor extends UpdateRequestProcessor
  public ConditionalCopyProcessor( UpdateRequestProcessor next) {
    super( next );

  public void processAdd(AddUpdateCommand cmd) throws IOException {
    SolrInputDocument doc = cmd.getSolrInputDocument();

    Object v = doc.getFieldValue( "popularity" );
    if( v != null ) {
      int pop = Integer.parseInt( v.toString() );
      if( pop > 5 ) {
        doc.addField( "cat", "popular" );

    // pass it up the chain

Script UpdateProcessors

SOLR-1725, to be committed for Solr 4.0 final release, adds a ScriptUpdateProcessor. There is a StatelessScriptUpdateProcessorFactory included to configure into your solrconfig.xml configuration file. The ScriptUpdateProcessor allows for Java scripting engines to be used during the Solr document update processing, allowing dramatic flexibility in expressing custom document processing before being indexed. (it also allows hooks to commit, delete, etc, but add will have the most common usage). More coming soon!

UpdateRequestProcessor (last edited 2016-06-06 14:59:22 by AlessandroBenedetti)