Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can copy 2 fields data to one field on Solr

Tags:

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?

like image 269
Mirodil Avatar asked Jun 22 '12 10:06

Mirodil


People also ask

What is multiValued field in Solr?

multiValued. If true, indicates that a single document might contain multiple values for this field type.

What is copy field in Solr?

copyField uses the matching glob from the source field for the dest field name into which the source content is copied. Copying is done at the stream source level and no copy feeds into another copy. This means that copy fields cannot be chained i.e. you cannot copy from here to there and then from there to elsewhere .

What are dynamic fields in Solr?

Dynamic fields allow Solr to index fields that you did not explicitly define in your schema. This is useful if you discover you have forgotten to define one or more fields. Dynamic fields can make your application less brittle by providing some flexibility in the documents you can add to Solr.


3 Answers

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>
like image 159
librucha Avatar answered Oct 03 '22 16:10

librucha


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.

like image 27
David Smiley Avatar answered Oct 03 '22 17:10

David Smiley


You could try to set store as multivalued

<field name="store" type="location" indexed="true" stored="true" multiValued="true" />
like image 32
Stelian Matei Avatar answered Oct 03 '22 16:10

Stelian Matei