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?
multiValued. If true, indicates that a single document might contain multiple values for this field type.
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 .
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.
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>
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.
You could try to set store
as multivalued
<field name="store" type="location" indexed="true" stored="true" multiValued="true" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With