更新 Solr 中的特定字段 [英] Update specific field in Solr

查看:41
本文介绍了更新 Solr 中的特定字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Solr6.2 并且想要更新文档中的特定字段,有点类似于关系数据库中的字段:update table_a set field_x = FIELD_x+1;

I'm using Solr6.2 and wanna update specific field in a document somewhat like that in relational db: update table_a set field_x = filed_x+1;

如何在 Solr 中实现?提前致谢.

How to acheive that in Solr? Thanks in advance.

推荐答案

为此,您需要将所有字段设置为已存储,因为这样您就可以使用 Solr 对 更新部分文档.

For this to work you'll need to have all fields set as stored, since you can then use Solr's support for Updating Parts of Documents.

然后您可以使用 inc 命令来增加文档中的字段:

You can then use the inc command to increment a field in a document:

{
    "id":"mydoc",
    "popularity":{"inc":20}
}

由于内部更新是检索文档、更改值、重新索引文档",因此所有字段都必须设置为已存储.如果您在 6.2 中使用默认的无架构 .. 架构 ..,则默认情况下存储所有字段.如果您使用自定义架构或通过架构 API 手动更改字段,则必须确保它们都设置为已存储.

Since internally an update is "retrieve document, change value, reindex document", all fields has to be set as stored. If you're using the default schemaless .. schema .. in 6.2, all fields are stored by default. If you're using a custom schema or has manually changed fields through the Schema API, you'll have to make sure they're all set as stored.

更新:

对于 SolrJ,这样的事情应该可以工作(来自 Yonik 的帖子):

For SolrJ, something like this should work (from Yonik's post):

SolrInputDocument doc = new SolrInputDocument();

doc.addField("id", "test");
Map<String, String> cmd2 = new HashMap<>();
cmd1.put("inc", "20");
doc.addField("field1", cmd1);
client.add(collection, doc);

这篇关于更新 Solr 中的特定字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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