简体   繁体   中英

On solr how can i copy selected values only from multi valued field to another multi valued field?

I have indexed solr one of the field is multivalued and it has different values in it and i want to copy selected values into new field.

Field1 has value a , b, c and want to copy into Field2 but only value a and c

The data is came from another instance of solr using dataimport processor="SolrEntityProcessor"

Am using solr 4.9

StatelessScriptUpdateProcessorFactory that enables the use of update processors implemented as scripts during update request.
When we are indexing we get multivalued Field1 and then copy those values which we needed into another field Field2 .
[Managed-Schema]

<field name="Field1" type="custom" multiValued="true" indexed="true" stored="true"/>
  <field name="Field2" type="custom" multiValued="true" indexed="true" stored="true"/>

Below is the sample update-script.js .

function processAdd(cmd) {
    doc = cmd.solrDoc;
    id = doc.getFieldValue("id");
    Field1 = doc.getFieldValues("Field1");
    logger.info("Size : "+Field1.size());
    for(i = 0; i < Field1.size();i++){
        if(Field1.get(i).equals("a") || Field1.get(i).equals("c")){
            doc.addField("Field2", Field1.get(i));
        }
    }
    logger.info("UpdateScript processed: "+id);

}
function processDelete(cmd) {
  // no-op
}

function processMergeIndexes(cmd) {
  // no-op
}

function processCommit(cmd) {
  // no-op
}

function processRollback(cmd) {
  // no-op
}

function finish() {
  // no-op
}

Add the StatelessScriptUpdateProcessorFactory processor to the updateRequestProcessorChain in solrconfig.xml.

<processor class="solr.StatelessScriptUpdateProcessorFactory">
   <str name="script">update-script.js</str>
 </processor>

What does it mean I want ? Solr can't read your mind. So, do you want to skip a specific value, an item in specific position, any item that does not match particular rules?

In all of the cases, most likely, you will use the UpdateRequestProcessor, but which specific one depends on what your business rule actually means.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM