Concat 2 fields in another field

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Concat 2 fields in another field

Alok Bhandari
Hello all ,

I am using solr 4.x , I have a requirement where I need to have a field which holds data from 2 fields concatenated using _. So for example I have 2 fields firstName and lastName , I want a third field which should hold firstName_lastName. Is there any existing concatenating component available or I need to write a custom updateProcessor which does this task. By the way need for having this third field is that I want to group on the firstname,lastName but as grouping does not support multiple fields to form single group I am using this trick. Hope I am clear .

Thanks .
Reply | Threaded
Open this post in threaded view
|

Re: Concat 2 fields in another field

Rafał Kuć-3
Hello!

You don't have to write custom component - you can use
ScriptUpdateProcessor - http://wiki.apache.org/solr/ScriptUpdateProcessor

--
Regards,
 Rafał Kuć
 Sematext :: http://sematext.com/ :: Solr - Lucene - ElasticSearch

> Hello all ,

> I am using solr 4.x , I have a requirement where I need to have a field
> which holds data from 2 fields concatenated using _. So for example I have 2
> fields firstName and lastName , I want a third field which should hold
> firstName_lastName. Is there any existing concatenating component available
> or I need to write a custom updateProcessor which does this task. By the way
> need for having this third field is that I want to group on the
> firstname,lastName but as grouping does not support multiple fields to form
> single group I am using this trick. Hope I am clear .

> Thanks .




> --
> View this message in context:
> http://lucene.472066.n3.nabble.com/Concat-2-fields-in-another-field-tp4086786.html
> Sent from the Solr - User mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|

Re: Concat 2 fields in another field

Alok Bhandari
Thanks for reply.

But I don't want to introduce any scripting in my code so want to know is there any Java component available for the same.
Reply | Threaded
Open this post in threaded view
|

RE: Concat 2 fields in another field

Markus Jelsma-2
You may be more interested in the ConcatFieldUpdateProcessorFactory:
http://lucene.apache.org/solr/4_1_0/solr-core/org/apache/solr/update/processor/ConcatFieldUpdateProcessorFactory.html

 
 
-----Original message-----

> From:Alok Bhandari <[hidden email]>
> Sent: Tuesday 27th August 2013 14:05
> To: [hidden email]
> Subject: Re: Concat 2 fields in another field
>
> Thanks for reply.
>
> But I don't want to introduce any scripting in my code so want to know is
> there any Java component available for the same.
>
>
>
> --
> View this message in context: http://lucene.472066.n3.nabble.com/Concat-2-fields-in-another-field-tp4086786p4086791.html
> Sent from the Solr - User mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|

Re: Concat 2 fields in another field

Federico Chiacchiaretta
Hi,
we do the same thing using an update request processor chain, this is the
snippet from solrconfig.xml

<updateRequestProcessorChain name="concatenation">
<processor class="solr.CloneFieldUpdateProcessorFactory"> <str name="source"
>firstname</str> <str name="dest">concatfield</str> </processor> <processor
class="solr.CloneFieldUpdateProcessorFactory"> <str name="source">lastname</
str> <str name="dest">concatfield</str> </processor> <processor class=
"solr.ConcatFieldUpdateProcessorFactory"> <str name="fieldName">concatfield
</str> <str name="delimiter">_</str> </processor>
<processor class="solr.LogUpdateProcessorFactory" /> <processor class=
"solr.RunUpdateProcessorFactory" />
</updateRequestProcessorChain>


Regards,
Federico Chiacchiaretta



2013/8/27 Markus Jelsma <[hidden email]>

> You may be more interested in the ConcatFieldUpdateProcessorFactory:
>
> http://lucene.apache.org/solr/4_1_0/solr-core/org/apache/solr/update/processor/ConcatFieldUpdateProcessorFactory.html
>
>
>
> -----Original message-----
> > From:Alok Bhandari <[hidden email]>
> > Sent: Tuesday 27th August 2013 14:05
> > To: [hidden email]
> > Subject: Re: Concat 2 fields in another field
> >
> > Thanks for reply.
> >
> > But I don't want to introduce any scripting in my code so want to know is
> > there any Java component available for the same.
> >
> >
> >
> > --
> > View this message in context:
> http://lucene.472066.n3.nabble.com/Concat-2-fields-in-another-field-tp4086786p4086791.html
> > Sent from the Solr - User mailing list archive at Nabble.com.
> >
>
Reply | Threaded
Open this post in threaded view
|

Re: Concat 2 fields in another field

Jack Krupansky-2
I have additional examples in the two most recent early access releases of
my book - variations on using the existing update processors.

-- Jack Krupansky

-----Original Message-----
From: Federico Chiacchiaretta
Sent: Tuesday, August 27, 2013 8:39 AM
To: [hidden email]
Subject: Re: Concat 2 fields in another field

Hi,
we do the same thing using an update request processor chain, this is the
snippet from solrconfig.xml

<updateRequestProcessorChain name="concatenation">
<processor class="solr.CloneFieldUpdateProcessorFactory"> <str name="source"
>firstname</str> <str name="dest">concatfield</str> </processor> <processor
class="solr.CloneFieldUpdateProcessorFactory"> <str name="source">lastname</
str> <str name="dest">concatfield</str> </processor> <processor class=
"solr.ConcatFieldUpdateProcessorFactory"> <str name="fieldName">concatfield
</str> <str name="delimiter">_</str> </processor>
<processor class="solr.LogUpdateProcessorFactory" /> <processor class=
"solr.RunUpdateProcessorFactory" />
</updateRequestProcessorChain>


Regards,
Federico Chiacchiaretta



2013/8/27 Markus Jelsma <[hidden email]>

> You may be more interested in the ConcatFieldUpdateProcessorFactory:
>
> http://lucene.apache.org/solr/4_1_0/solr-core/org/apache/solr/update/processor/ConcatFieldUpdateProcessorFactory.html
>
>
>
> -----Original message-----
> > From:Alok Bhandari <[hidden email]>
> > Sent: Tuesday 27th August 2013 14:05
> > To: [hidden email]
> > Subject: Re: Concat 2 fields in another field
> >
> > Thanks for reply.
> >
> > But I don't want to introduce any scripting in my code so want to know
> > is
> > there any Java component available for the same.
> >
> >
> >
> > --
> > View this message in context:
> http://lucene.472066.n3.nabble.com/Concat-2-fields-in-another-field-tp4086786p4086791.html
> > Sent from the Solr - User mailing list archive at Nabble.com.
> >
>

Reply | Threaded
Open this post in threaded view
|

Re: Concat 2 fields in another field

Billnbell
If for search just copyField into a multivalued field....

Or do it on indexing using DIH or code. A rhino script works too.

Bill Bell
Sent from mobile


On Aug 27, 2013, at 7:15 AM, "Jack Krupansky" <[hidden email]> wrote:

> I have additional examples in the two most recent early access releases of my book - variations on using the existing update processors.
>
> -- Jack Krupansky
>
> -----Original Message----- From: Federico Chiacchiaretta
> Sent: Tuesday, August 27, 2013 8:39 AM
> To: [hidden email]
> Subject: Re: Concat 2 fields in another field
>
> Hi,
> we do the same thing using an update request processor chain, this is the
> snippet from solrconfig.xml
>
> <updateRequestProcessorChain name="concatenation">
> <processor class="solr.CloneFieldUpdateProcessorFactory"> <str name="source"
>> firstname</str> <str name="dest">concatfield</str> </processor> <processor
> class="solr.CloneFieldUpdateProcessorFactory"> <str name="source">lastname</
> str> <str name="dest">concatfield</str> </processor> <processor class=
> "solr.ConcatFieldUpdateProcessorFactory"> <str name="fieldName">concatfield
> </str> <str name="delimiter">_</str> </processor>
> <processor class="solr.LogUpdateProcessorFactory" /> <processor class=
> "solr.RunUpdateProcessorFactory" />
> </updateRequestProcessorChain>
>
>
> Regards,
> Federico Chiacchiaretta
>
>
>
> 2013/8/27 Markus Jelsma <[hidden email]>
>
>> You may be more interested in the ConcatFieldUpdateProcessorFactory:
>>
>> http://lucene.apache.org/solr/4_1_0/solr-core/org/apache/solr/update/processor/ConcatFieldUpdateProcessorFactory.html
>>
>>
>>
>> -----Original message-----
>> > From:Alok Bhandari <[hidden email]>
>> > Sent: Tuesday 27th August 2013 14:05
>> > To: [hidden email]
>> > Subject: Re: Concat 2 fields in another field
>> >
>> > Thanks for reply.
>> >
>> > But I don't want to introduce any scripting in my code so want to know > is
>> > there any Java component available for the same.
>> >
>> >
>> >
>> > --
>> > View this message in context:
>> http://lucene.472066.n3.nabble.com/Concat-2-fields-in-another-field-tp4086786p4086791.html
>> > Sent from the Solr - User mailing list archive at Nabble.com.
>> >
>
Reply | Threaded
Open this post in threaded view
|

Re: Concat 2 fields in another field

Alok Bhandari
In reply to this post by Federico Chiacchiaretta
Hi all,

thanks for your replies. I have managed to do this by writing custom updateprocessor and configured it as bellow

<processor class="com.test.solr.update.CustomConcatFieldUpdateprocessorFactory">
                 <str name="field">firstName</str>
                 <str name="field">lastName</str>
                  <str name="dest">fullName</str>
                 <str name="delimiter">_</str>
</processor>.

Federico Chiacchiaretta , I have tried the option mentioned by you but on frequent update of the document it keeps on adding the value multiple times which I don't want . In my custom component I checked for existing value and if its empty then I have updated it by fN_lN.

Thanks a lot for quick replies.