Mirodil
Mirodil

Reputation: 2329

How can copy 2 fields data to one field on Solr

I have a document in solr with Lat and Lng fields. I need to add a new field called store containing data taken from both the Lat and Lng. I tried to use copyField field but I got the error:

Field store is not multivalued and destination for multiple copyFields (2)

Here is my configuration:

<fields>
  <field name="lat" type="sdouble" indexed="true" stored="true" required="true" multiValued="false" />
  <field name="lng" type="sdouble" indexed="true" stored="true" required="true" multiValued="false" /> 
  <field name="store" type="text" indexed="true" stored="true"/>
</fields> 

<copyField source="lat" dest="store"/> 
<copyField source="lng" dest="store"/> 

Is it possible to copy the content of two fields within the same destination field?

Upvotes: 8

Views: 20066

Answers (4)

librucha
librucha

Reputation: 685

Maybe is it outdated but you can use "updateRequestProcessorChain"

<updateRequestProcessorChain name="composite-position">
  <processor class="solr.CloneFieldUpdateProcessorFactory">
    <str name="source">lat</str>
    <str name="source">lng</str>
    <str name="dest">store</str>
  </processor>
  <processor class="solr.ConcatFieldUpdateProcessorFactory">
    <str name="fieldName">store</str>
    <str name="delimiter">;</str>
  </processor>
  <processor class="solr.LogUpdateProcessorFactory" />
  <processor class="solr.RunUpdateProcessorFactory" />
</updateRequestProcessorChain>

Upvotes: 7

vuky
vuky

Reputation: 603

You can try something like that:

Two double in one location

if you can use DIH (Data Importer Handler). Hope thet will help!

Upvotes: 0

David Smiley
David Smiley

Reputation: 4141

Taking your question without context:

Is it possible to copy the content of two fields within the same destination field?"

The answer is yes, surely. The example schema does this with to copy multiple fields to a common "text" field (multiValued) to make searching by one field simpler.

But looking at more context, what you are actually trying to do is determine if Solr's schema.xml with copyField can take an input pair of fields (lat and lon in your case) and concatenate them with an intermediate comma to a particular field. The answer is no. You'll have to prepare the data this way when giving it to Solr, or use a DIH transformer if you are using the DIH (the DataImportHandler). I hesitate to suggest an alternative, but as a hack, you might try putting lat and lon into store_0_coordinate and store_1_coordinate (or maybe it's the other way around). But really, this isn't a recommended approach even if it might work.

Upvotes: 6

Stelian Matei
Stelian Matei

Reputation: 11623

You could try to set store as multivalued

<field name="store" type="location" indexed="true" stored="true" multiValued="true" />

Upvotes: 3

Related Questions