org.apache.solr.update.processor

Class AddSchemaFieldsUpdateProcessorFactory

  • All Implemented Interfaces:
    UpdateRequestProcessorFactory.RunAlways, NamedListInitializedPlugin, SolrCoreAware


    public class AddSchemaFieldsUpdateProcessorFactory
    extends UpdateRequestProcessorFactory
    implements SolrCoreAware, UpdateRequestProcessorFactory.RunAlways

    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.

    By default, this processor selects all fields that don't match a schema field or dynamic field. The "fieldName" and "fieldRegex" selectors may be specified to further restrict the selected fields, but the other selectors ("typeName", "typeClass", and "fieldNameMatchesSchemaField") may not be specified.

    This processor is configured to map from each field's values' class(es) to the schema field type that will be used when adding the new field to the schema. All new fields are then added to the schema in a single batch. If schema addition fails for any field, addition is re-attempted only for those that don’t match any schema field. This process is repeated, either until all new fields are successfully added, or until there are no new fields (presumably because the fields that were new when this processor started its work were subsequently added by a different update request, possibly on a different node).

    This processor takes as configuration a sequence of zero or more "typeMapping"-s from one or more "valueClass"-s, specified as either an <arr> of <str>, or multiple <str> with the same name, to an existing schema "fieldType".

    If more than one "valueClass" is specified in a "typeMapping", field values with any of the specified "valueClass"-s will be mapped to the specified target "fieldType". The "typeMapping"-s are attempted in the specified order; if a field value's class is not specified in a "valueClass", the next "typeMapping" is attempted. If no "typeMapping" succeeds, then the specified "defaultFieldType" is used.

    Example configuration:

     <processor class="solr.AddSchemaFieldsUpdateProcessorFactory">
       <str name="defaultFieldType">text_general</str>
       <lst name="typeMapping">
         <str name="valueClass">Boolean</str>
         <str name="fieldType">boolean</str>
       </lst>
       <lst name="typeMapping">
         <str name="valueClass">Integer</str>
         <str name="fieldType">tint</str>
       </lst>
       <lst name="typeMapping">
         <str name="valueClass">Float</str>
         <str name="fieldType">tfloat</str>
       </lst>
       <lst name="typeMapping">
         <str name="valueClass">Date</str>
         <str name="fieldType">tdate</str>
       </lst>
       <lst name="typeMapping">
         <str name="valueClass">Long</str>
         <str name="valueClass">Integer</str>
         <str name="fieldType">tlong</str>
       </lst>
       <lst name="typeMapping">
         <arr name="valueClass">
           <str>Double</str>
           <str>Float</str>
         </arr>
         <str name="fieldType">tdouble</str>
       </lst>
     </processor>