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

家住魔仙堡 提交于 2019-12-12 03:29:16

问题


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


回答1:


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.




回答2:


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>


来源:https://stackoverflow.com/questions/40761435/on-solr-how-can-i-copy-selected-values-only-from-multi-valued-field-to-another-m

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!