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

Every update request received by Solr is run through a chain of plugins known as Update Request Processors, or URPs. This can be useful, for example, to add a field to the document being indexed; to change the value of a particular field; or to drop an update if the incoming document doesn't fulfill certain criteria. In fact, a surprisingly large number of features in Solr are implemented as Update Processors and therefore it is necessary to understand how such plugins work and where are they configured.

Topics in this section:

Anatomy and Lifecycle

An Update Request Processor is created as part of a chain of one or more update processors. Solr creates a default update request processor chain comprising of a few update request processors which enable essential Solr features. This default chain is used to process every update request unless a user chooses to configure and specify a different custom update request processor chain.

The easiest way to describe an Update Request Processor is to look at the Javadocs of the abstract class UpdateRequestProcessor. Every UpdateRequestProcessor must have a corresponding factory class which extends UpdateRequestProcessorFactory. This factory class is used by Solr to create a new instance of this plugin. Such a design provides two benefits:

  1. An update request processor need not be thread safe because it is used by one and only one request thread and destroyed once the request is complete.
  2. The factory class can accept configuration parameters and maintain any state that may be required between requests. The factory class must be thread-safe.

Every update request processor chain is constructed during loading of a Solr core and cached until the core is unloaded. Each UpdateRequestProcessorFactory specified in the chain is also instantiated and initialized with configuration that may have been specified in solrconfig.xml.

When an update request is received by Solr, it looks up the update chain to be used for this request. A new instance of each UpdateRequestProcessor specified in the chain is created using the corresponding factory. The update request is parsed into corresponding UpdateCommand objects which are run through the chain. Each UpdateRequestProcessor instance is responsible for invoking the next plugin in the chain. It can choose to short circuit the chain by not invoking the next processor and even abort further processing by throwing an exception.

A single update request may contain a batch of multiple new documents or deletes and therefore the corresponding processXXX methods of an UpdateRequestProcessor will be invoked multiple times for every individual update. However, it is guaranteed that a single thread will serially invoke these methods.

Configuration

Update request processors chains can be created by either creating the whole chain directly in solrconfig.xml or by creating individual update processors in solrconfig.xml and then dynamically creating the chain at run-time by specifying all processors via request parameters.

However, before we understand how to configure update processor chains, we must learn about the default update processor chain because it provides essential features which are needed in most custom request processor chains as well.

Default Update Request Processor Chain

In case no update processor chains are configured in solrconfig.xml, Solr will automatically create a default update processor chain which will be used for all update requests. This default update processor chain consists of the following processors (in order):

  1. LogUpdateProcessorFactory - Tracks the commands processed during this request and logs them
  2. DistributedUpdateProcessorFactory - Responsible for distributing update requests to the right node e.g., routing requests to the leader of the right shard and distributing updates from the leader to each replica. This processor is activated only in SolrCloud mode.
  3. RunUpdateProcessorFactory - Executes the update using internal Solr APIs.

Each of these perform an essential function and as such any custom chain usually contain all of these processors. The RunUpdateProcessorFactory is usually the last update processor in any custom chain.

Custom Update Request Processor Chain

The following example demonstrates how a custom chain can be configured inside solrconfig.xml.

updateRequestProcessorChain

In the above example, a new update processor chain named "dedupe" is created with SignatureUpdateProcessorFactory, LogUpdateProcessorFactory and RunUpdateProcessorFactory in the chain. The SignatureUpdateProcessorFactory is further configured with different parameters such as "signatureField", "overwriteDupes", etc. This chain is an example of how Solr can be configured to perform de-duplication of documents by calculating a signature using the value of name, features, cat fields which is then used as the "id" field. As you may have noticed, this chain does not specify the DistributedUpdateProcessorFactory. Because this processor is critical for Solr to operate properly, Solr will automatically insert DistributedUpdateProcessorFactory in any chain that does not include it just prior to the RunUpdateProcessorFactory.

RunUpdateProcessorFactory

Do not forget to add RunUpdateProcessorFactory at the end of any chains you define in solrconfig.xml. Otherwise update requests processed by that chain will not actually affect the indexed data.

Configuring Individual Processors as Top-Level Plugins

Update request processors can also be configured independent of a chain in solrconfig.xml.

updateProcessor

In this case, an instance of SignatureUpdateProcessorFactory is configured with the name "signature" and a RemoveBlankFieldUpdateProcessorFactory is defined with the name "remove_blanks". Once the above has been specified in solrconfig.xml, we can be refer to them in update request processor chains in solrconfig.xml as follows:

updateRequestProcessorChains and updateProcessors

Update Processors in SolrCloud

In a single node, stand-alone Solr, each update is run through all the update processors in a chain exactly once. But the behavior of update request processors in SolrCloud deserves special consideration.

A critical SolrCloud functionality is the routing and distributing of requests. For update requests this routing is implemented by the DistributedUpdateRequestProcessor, and this processor is given a special status by Solr due to its important function.

In SolrCloud mode, all processors in the chain before the DistributedUpdateProcessor are run on the first node that receives an update from the client, regardless of this node's status as a leader or replica.  The DistributedUpdateProcessor then forwards the update to the appropriate shard leader for the update (or to multiple leaders in the event of an update that affects multiple documents, such as a delete by query or commit). The shard leader uses a transaction log to apply Atomic Updates & Optimistic Concurrency and then forwards the update to all of the shard replicas. The leader and each replica run all of the processors in the chain that are listed after the DistributedUpdateProcessor.

For example, consider the "dedupe" chain which we saw in a section above. Assume that a 3-node SolrCloud cluster exists where node A hosts the leader of shard1, node B hosts the leader of shard2 and node C hosts the replica of shard2. Assume that an update request is sent to node A which forwards the update to node B (because the update belongs to shard2) which then distributes the update to its replica node C. Let's see what happens at each node:

  • Node A: Runs the update through the SignatureUpdateProcessor (which computes the signature and puts it in the "id" field), then LogUpdateProcessor and then DistributedUpdateProcessor. This processor determines that the update actually belongs to node B and is forwarded to node B. The update is not processed further. This is required because the next processor, RunUpdateProcessor, will execute the update against the local shard1 index which would lead to duplicate data on shard1 and shard2.
  • Node B: Receives the update and sees that it was forwarded by another node. The update is directly sent to DistributedUpdateProcessor because it has already been through the SignatureUpdateProcessor on node A and doing the same signature computation again would be redundant. The DistributedUpdateProcessor determines that the update indeed belongs to this node, distributes it to its replica on Node C and then forwards the update further in the chain to RunUpdateProcessor.
  • Node C: Receives the update and sees that it was distributed by its leader. The update is directly sent to DistributedUpdateProcessor which performs some consistency checks and forwards the update further in the chain to RunUpdateProcessor.

In summary:

  1. All processors before DistributedUpdateProcessor are only run on the first node that receives an update request whether it be a forwarding node (e.g., node A in the above example) or a leader (e.g., node B). We call these "pre-processors" or just "processors".
  2. All processors after DistributedUpdateProcessor run only on the leader and the replica nodes. They are not executed on forwarding nodes. Such processors are called "post-processors".

In the previous section, we saw that the updateRequestProcessorChain was configured with processor="remove_blanks, signature". This means that such processors are of the #1 kind and are run only on the forwarding nodes. Similarly, we can configure them as the #2 kind by specifying with the attribute "post-processor" as follows:

post-processors

However executing a processor only on the forwarding nodes is a great way of distributing an expensive computation such as de-duplication across a SolrCloud cluster by sending requests randomly via a load balancer. Otherwise the expensive computation is repeated on both the leader and replica nodes.

Pre-processors and Atomic Updates

Because DistributedUpdateProcessor is responsible for processing Atomic Updates into full documents on the leader node, this means that pre-processors which are executed only on the forwarding nodes can only operate on the partial document. If you have a processor which must process a full document then the only choice is to specify it as a post-processor.

Custom update chain post-processors may never be invoked on a recovering replica

While a replica is in recovery, inbound update requests are buffered to the transaction log.  After recovery has completed successfully, those buffered update requests are replayed.  As of this writing, however, custom update chain post-processors are never invoked for buffered update requests.  See SOLR-8030.  To work around this problem until SOLR-8030 has been fixed, avoid specifying post-processors in custom update chains.

Using Custom Chains

update.chain Request Parameter

The update.chain parameter can be used in any update request to choose a custom chain which has been configured in solrconfig.xml. For example, in order to choose the "dedupe" chain described in a previous section, one can issue the following request:

update.chain

The above should dedupe the two identical documents and index only one of them.

Processor & Post-Processor Request Parameters

We can dynamically construct a custom update request processor chain using the "processor" and "post-processor" request parameters. Multiple processors can be specified as a comma-separated value for these two parameters. For example:

Constructing a chain at request time

In the first example, Solr will dynamically create a chain which has "signature" and "remove_blanks" as pre-processors to be executed only on the forwarding node where as in the second example, "remove_blanks" will be executed as a pre-processor and "signature" will be executed on the leader and replicas as a post-processor. 

Configuring a Custom Chain as a Default

We can also specify a custom chain to be used by default for all requests sent to specific update handlers instead of specifying the names in request parameters for each request.

This can be done by adding either "update.chain" or "processor" and "post-processor" as default parameter for a given path which can be done either via initParams or by adding them in a "defaults" section which is supported by all request handlers.

The following is an initParam defined in the schemaless configuration which applies a custom update chain to all request handlers starting with "/update/".

InitParams

Alternately, one can achieve a similar effect using the "defaults" as shown in the example below:

defaults

Update Request Processor Factories

What follows are brief descriptions of the currently available update request processors. An UpdateRequestProcessorFactory can be integrated into an update chain in solrconfig.xml as necessary. You are strongly urged to examine the Javadocs for these classes; these descriptions are abridged snippets taken for the most part from the Javadocs.

General Use UpdateProcessorFactories

  • AddSchemaFieldsUpdateProcessorFactory: This processor will dynamically add fields to the schema if an input document contains one or more fields that don't match any field or dynamic field in the schema.
  • ClassificationUpdateProcessorFactory: This processor uses Lucene's classification module to provide simple document classification. See https://wiki.apache.org/solr/SolrClassification for more details on how to use this processor.
  • CloneFieldUpdateProcessorFactory: Clones the values found in any matching source field into  the configured dest field.
  • DefaultValueUpdateProcessorFactory: A simple processor that adds a default value to any document which does not already have a value in fieldName.
  • DocBasedVersionConstraintsProcessorFactory: This Factory generates an UpdateProcessor that helps to enforce version constraints on documents based on per-document version numbers using a configured name of a versionField.
  • DocExpirationUpdateProcessorFactory: Update Processor Factory for managing automatic "expiration" of documents.
  • FieldNameMutatingUpdateProcessorFactory: Modifies field names by replacing all matches to the configured pattern with the configured replacement.
  • IgnoreCommitOptimizeUpdateProcessorFactory: Allows you to ignore commit and/or optimize requests from client applications when running in SolrCloud mode, for more information, see: Shards and Indexing Data in SolrCloud
  • RegexpBoostProcessorFactory: A processor which will match content of "inputField" against regular expressions found in "boostFilename", and if it matches will return the corresponding boost value from the file and output this to "boostField" as a double value.
  • SignatureUpdateProcessorFactory: Uses a defined set of fields to generate a hash "signature" for the document. Useful for only indexing one copy of "similar" documents.
  • StatelessScriptUpdateProcessorFactory: An update request processor factory that enables the use of update processors implemented as scripts.
  • TimestampUpdateProcessorFactory: An update processor that adds a newly generated date value of "NOW" to any document being added that does not already have a value in the specified field.
  • URLClassifyProcessorFactory: Update processor which examines a URL and outputs to various other fields with characteristics of that URL, including length, number of path levels, whether it is a top level URL (levels==0), whether it looks like a landing/index page, a canonical representation of the URL (e.g., stripping index.html), the domain and path parts of the URL, etc.
  • UUIDUpdateProcessorFactory: An update processor that adds a newly generated UUID value to any document being added that does not already have a value in the specified field.

FieldMutatingUpdateProcessorFactory Derived Factories

These factories all provide functionality to modify fields in a document as they're being indexed. When using any of these factories, please consult the FieldMutatingUpdateProcessorFactory javadocs for details on the common options they all support for configuring which fields are modified.

Update Processor Factories That Can Be Loaded as Plugins

These processors are included in Solr releases as "contribs", and require additional jars loaded at runtime. See the README files associated with each contrib for details:

Update Processor Factories You Should Not Modify or Remove

These are listed for completeness, but are part of the Solr infrastructure, particularly SolrCloud. Other than insuring you do not remove them when modifying the update request handlers (or any copies you make), you will rarely, if ever, need to change these.

  • DistributedUpdateProcessorFactory: Used to distribute updates to all necessary nodes.
    • NoOpDistributingUpdateProcessorFactory: An alternative No-Op implementation of DistributingUpdateProcessorFactory that always returns null. Designed for experts who want to bypass distributed updates and use their own custom update logic.
  • LogUpdateProcessorFactory: A logging processor.  This keeps track of all commands that have passed through the chain and prints them on finish().
  • RunUpdateProcessorFactory: Executes the update commands using the underlying UpdateHandler. Almost all processor chains should end with an instance of RunUpdateProcessorFactory unless the user is explicitly  executing the update commands in an alternative custom UpdateRequestProcessorFactory.

Update Processors That Can Be Used at Runtime

TemplateUpdateProcessorFactory

The TemplateUpdateProcessorFactory can be used to add new fields to documents based on a template pattern.

This can be used directly in a request without any configuration. To enable this processor, use the parameter processor=Template. The template parameter Template.field (multivalued) define the field to add and the pattern. Templates may contain placeholders which refer to other fields in the document. You can have multiple Template.field parameters in a single request.

For example:

The above example would add a new field to the document called fullName. The fields firstName and lastName are supplied from the document fields. If either of them is missing, that part is replaced with an empty string. If those fields are multi-valued, only the first value is used.

 

 

 

  • No labels

10 Comments

  1. Also, a FieldNameMutatingUpdateProcessorFactory, which cleans up actual field names if they have space. Helps with field names auto-generated by something like Tika.

    1. Thanks for pointing out the omission, Alexandre.  I've added it.

  2. I understand that we can refer to preconfigured processors by name like this

    processor="remove_blanks,signature"

    But it seems as if you then must define all processors as preconfigured, named ones, and that any explicitly configured "processor" tags will come after the ones in the named list? Is that correct?

    I'd wish for a syntax to reference named processors with a tag to be able to mix and match predefined and ad-hoc:

    <processor ref="remove_blanks"/>

    Is there a way to do this already or should I open a JIRA?

    1. sorry for this very late response. Yes the processor tags will come after all the other processors and right before the DistributedUpdateprocessorFactory

  3. Is there any documentation available that can show how to access SOLR document metadata like "title","filename" etc in UIMA. Please guide me to the reference.

     

  4. Should we add a warning here about the fact that on replay, buffered tlog entries never get update chain post-processors run on them, possibly leading to disparities in indexed data between replicas, and therefore SolrCloud configurations should avoid specifying post-processors?  See SOLR-8030 (and a concrete example of this problem: SOLR-9883).

      1. I'll add a warning box to the SolrCloud section with this text:

        While a replica is in recovery, inbound update requests are buffered to the transaction log.  After recovery has completed successfully, those buffered update requests are replayed.  As of this writing, however, custom update chain post-processors are never invoked for buffered update requests.  See SOLR-8030.  To workaround this problem until SOLR-8030 has been fixed, avoid specifying post-processors in custom update chains.

    1. Good edit Steve.  A related gotcha is setting default="true" on a chain, which is the chain processed by replay.  But it replays the entire chain, and some URPs may not be written to expect being called effectively twice.  Fortunately it appears setting a chain as "default" directly doesn't seem to be documented... so if we keep it that way then it won't hurt people I guess.  It hurt me because I knew it was possible and did it (wink)