有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何减少Solr中多值字段的长度

Solr中有一个多值字段,我们希望减少它的长度。 样本结果响应如下所示:

 response": {
     "numFound": 1,
     "start": 0,
     "docs": [
       {
         "created_date": "2016-11-23T13:47:46.55Z",
         "solr_index_date": "2016-12-01T08:21:59.78Z",
         "modified_date": "2016-12-13T08:45:44.507Z",        
         "id": "FEAE38C2-ABFF-4F0C-8AFD-9B8F51036D8A",        
         "Field1": [
           "false",
           "true",
           "true",
           .....   <= 1200 items
         ]
       }
         ]   
     }

我们有大数据,一些TB,我们正在寻找一种优化的方法来更改Solr中的所有文档,并修改Field1,使其仅包含前100个项目

不需要编写脚本来手动获取文档、进行调整并将其推回到solr,这样的事情就可以完成吗?有没有人有过类似的经历?谢谢


共 (1) 个答案

  1. # 1 楼答案

    我们已经面临这个问题。但是我们使用两个集合来解决这个问题。使用SoleEntityProcessor将文档从一个集合移动到另一个集合

    [SolrEntityProcessor]
    
    <dataConfig>
      <document>
        <entity name="sep" processor="SolrEntityProcessor" url="http://localhost:8983/solr/db" query="*:*"/>
      </document>
    </dataConfig>
    

    移动时,将该文档通过updateRequestProcessorChain传递,在那里我们可以编写无状态脚本UpdateProcessorFactory来编辑文档或截断多值字段
    在无状态ScriptUpdateProcessorFactory中,您可以获取字段并应用操作,然后重置该字段

    [StatelessScriptUpdateProcessorFactory]
    
    function processAdd(cmd) {
        doc = cmd.solrDoc;
        multiDate = doc.getFieldValue("multiValueField");
        //Apply your operation to above field
        //doc.setField("multiValueField",value);
    
    }
    function processDelete(cmd) {
      // no-op
    }
    
    function processMergeIndexes(cmd) {
      // no-op
    }
    
    function processCommit(cmd) {
      // no-op
    }
    
    function processRollback(cmd) {
      // no-op
    }
    
    function finish() {
      // no-op
    }
    

    有关无状态ScriptUpdateProcessorFactory的更多信息,可以参考此问题 On solr how can i copy selected values only from multi valued field to another multi valued field? 在其中,他们使用脚本编辑多值字段