You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@solr.apache.org by Yirmiyahu Fischer <yf...@signature-it.com> on 2022/06/01 09:27:42 UTC

concatinating fields via schema

How do I create a concatenated field via schema.xml?

I am using Solr, version 8.2
In my schema, fields ending in "_s" are of string type, fields ending in
"_t" are of text type, and fields ending in "_txt" are multivalue text type.

   <dynamicField name="*_s"  type="string"  indexed="true"  stored="true" />
   <dynamicField name="*_t"  type="text_general"    indexed="true"
 stored="true"/>
   <dynamicField name="*_txt" type="text_general"   indexed="true"
 stored="true" multiValued="true"/>

I need to create a field that concatenates the fields BrandName_s and
ManufacturerNo_s

I have tried

    <copyField source="BrandName_s" dest="BrandMfgConcat_t" />
    <copyField source="ManufacturerNo_s" dest="BrandMfgConcat_t" />

However, when indexing, I get an error.
Error adding field 'ManufacturerNo_s'='6852806' msg=Multiple values
encountered for non multiValued copy field BrandMfgConcat_t: 6852806

I tried

    <copyField source="BrandName_s" dest="BrandMfgConcat_txt" />
    <copyField source="ManufacturerNo_s" dest="BrandMfgConcat_txt" />

However, the resulting field BrandMfgConcat_txt is an array of the 2
values, not a concatenation.

I tried

    <updateRequestProcessorChain name="concatFields">
        <processor class="solr.CloneFieldUpdateProcessorFactory">
            <str name="source">BrandName_s</str>
            <str name="source">ManufacturerNo_s</str>
            <str name="dest">BrandMfgConcat_t</str>
        </processor>
        <processor class="solr.ConcatFieldUpdateProcessorFactory">
            <str name="fieldName">BrandMfgConcat_t</str>
        </processor>
        <processor class="solr.LogUpdateProcessorFactory" />
        <processor class="solr.RunUpdateProcessorFactory" />
    </updateRequestProcessorChain>

However, after indexing, the field BrandMfgConcat_t does not appear in the
record


*Yirmiyahu Fischer*

*Senior Developer |  **Tel**:* *03-9578900 *

*E**mail: **yfischer@signature-it.com* <yf...@signature-it.com>* | **W*
*eb: **www.signature-it.com* <http://www.signature-it.com/>

Re: concatinating fields via schema

Posted by Shawn Heisey <ap...@elyograg.org>.
On 6/1/2022 3:27 AM, Yirmiyahu Fischer wrote:
> I tried
>
>      <updateRequestProcessorChain name="concatFields">
>          <processor class="solr.CloneFieldUpdateProcessorFactory">
>              <str name="source">BrandName_s</str>
>              <str name="source">ManufacturerNo_s</str>
>              <str name="dest">BrandMfgConcat_t</str>
>          </processor>
>          <processor class="solr.ConcatFieldUpdateProcessorFactory">
>              <str name="fieldName">BrandMfgConcat_t</str>
>          </processor>
>          <processor class="solr.LogUpdateProcessorFactory" />
>          <processor class="solr.RunUpdateProcessorFactory" />
>      </updateRequestProcessorChain>
>
> However, after indexing, the field BrandMfgConcat_t does not appear in the
> record

I bet that you haven't done anything to actually tell Solr to use that 
update processor.

I put this in my config:

     <updateRequestProcessorChain name="concatFields" default="true">
         <processor class="solr.CloneFieldUpdateProcessorFactory">
             <str name="source">s1</str>
             <str name="source">s2</str>
             <str name="dest">s3</str>
         </processor>
         <processor class="solr.ConcatFieldUpdateProcessorFactory">
             <str name="fieldName">s3</str>
             <str name="delimiter"> </str>
         </processor>
         <processor class="solr.LogUpdateProcessorFactory" />
         <processor class="solr.RunUpdateProcessorFactory" />
     </updateRequestProcessorChain>

And then indexed a doc with s1 and s2 fields, and very deliberately 
excluding the s3 field.  This is what I get when querying for that doc:

|<result name="response" numFound="1" start="0" numFoundExact="true"> 
<doc> <str name="id">144</str> <long name="uid">144</long> <str 
name="box">144</str> <str name="user">144</str> <str 
name="s1">Test</str> <str name="s2">Doc</str> <str name="s3">Test 
Doc</str> <long name="_version_">1734426113514405888</long></doc> 
</result> The major difference between your config and mine is that I 
marked the update processor as default, which means that it will always 
be used unless another is specified. Thanks, Shawn |