Solr DIH 可以进行原子更新吗?` [英] Can Solr DIH do atomic updates?`

查看:22
本文介绍了Solr DIH 可以进行原子更新吗?`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

借助 Solr 4,可以对索引中的现有文档进行原子(部分)更新.IE.可以匹配文档 ID 并仅替换一个字段的内容,或向多值字段添加更多条目:http://wiki.apache.org/solr/Atomic_Updates

With Solr 4 came the ability to do atomic (partial) updates on existing documents within the index. I.e. one can match on the document ID and replace the contents of just one field, or add further entries to multivalued fields: http://wiki.apache.org/solr/Atomic_Updates

可以从 DataImportHandler (DIH) 进行原子更新吗?

Can atomic updates be done from DataImportHandler (DIH)?

推荐答案

我通过反复试验发现 ScriptTransformer 的答案是肯定的.

The answer is "yes" with the ScriptTransformer, I discovered through trial and error.

Solr 文档展示了如何使用set"、add"或inc"向字段节点添加更新属性.如果我创建一个具有必要更新属性的测试 XML 文件,它在传递给常规更新处理程序时工作正常.但是,当传递给 DIH 时——即使没有任何转换——更新属性会被完全忽略.

The Solr documentation shows how to add an update attribute to a field node with "set", "add" or "inc". If I create a test XML file with the requisite update attribute, it works fine when passed to the regular update handler. But, when passed to DIH - even without any transformation - the update attributes get ignored completely.

这是我用来重新引入更新属性并使原子更新工作的脚本转换器的简化版本.请注意 Java HashMap 的使用.

Here's a simplified version of the script transformer I used to reintroduce the update attribute and get atomic updates working. Note the use of the Java HashMap.

var atomicTransformer = function (row) {
    var authorMap = new java.util.HashMap();
    var author = String(row.get('author'));
    authorMap.put('add', author);
    row.put('author', authorMap);
};

这会在 DIH 调试模式下生成以下 JSON:

This produces the following JSON in DIH debug mode:

{
    "id": [
        123
    ],
    "author": [
        {
            "add": "Smith, J"
        }
    ]
}

多值字段也没有问题:将 ArrayList 而不是字符串传递给 HashMap.

Multivalued fields are also no problem: pass in an ArrayList to the HashMap instead of a string.

var atomicTransformer = function (row) {
    var fruits = new java.util.ArrayList();
    fruits.add("banana");
    fruits.add("apple");
    fruits.add("pear");
    var fruitMap = new java.util.HashMap();
    fruitMap.put('add', fruits);
    row.put('fruit', fruitMap);
}

这篇关于Solr DIH 可以进行原子更新吗?`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆