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

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

问题描述

我正在使用Solr6.2,想要更新文档中的特定字段,就像在关系数据库中一样:update table_a set field_x = filed_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中使用默认的无模式.. schema ..,则默认情况下将存储所有字段.如果您使用的是自定义架构,或者已通过Schema 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天全站免登陆