Search code examples
javasolrsolrj

Solr: Is it possible to call the "concat" function in the source of the "copyField"?


For example if I define the "copyField" below, the solr will throw this exception when startup: org.apache.solr.common.SolrException: copyField source :'concat('i1', id1)' is not a glob and doesn't match any explicit field or dynamicField.

<copyField source="concat('i1', id1)" dest="test" />
<copyField source="concat('i2', id2)" dest="test" />

But "concat('i1', id1)" can set to the "fl" of the query request without any errors.


Solution

  • You can archive the same with the help of Update request Processors of Solr

    You can use the ConcatFieldUpdateProcessorFactory :

    Concatenates multiple values for fields matching the specified conditions using a configurable delimiter.

    For Example :

    1. Add a new updateRequestProcessorChain to solrconfig.xml:
    <updateRequestProcessorChain name="concatFields">
      <processor class="solr.CloneFieldUpdateProcessorFactory"> 
          <str name="source">field1</str> 
          <str name="dest">field4</str> 
        </processor> 
      <processor class="solr.ConcatFieldUpdateProcessorFactory"> 
          <str name="fieldName">field4</str> 
          <str name="delimiter">_</str> 
        </processor>
        <processor class="solr.LogUpdateProcessorFactory" /> 
        <processor class="solr.RunUpdateProcessorFactory" />
    </updateRequestProcessorChain>
    
    1. Add that chain to the appropriate update handler
    <requestHandler name="/update/csv" class="solr.UpdateRequestHandler">
             <lst name="defaults">
             <str name="stream.contentType">application/csv</str>
             <str name="update.chain">concatFields</str>    </lst> </requestHandler>
    

    More details on the Update processors are found on the link below. Update Request Processors

    Note : Restart the Solr server and to index new documents.