使用 solrj 更新文档字段
我想编辑 solr 中归档的文档,例如编辑作者姓名,所以我在 solrj 中使用以下代码:
params.set("literal.author","anaconda")
但架构中的作者 multivalued="true" ,因为“anaconde”不会替换为它以前的名称,并且添加到作者姓名的末尾,此外,如果我省略多值字段或将其设置为 false,则在使用新作者字段重新索引文件时会发生错误请求异常,我该如何解决此问题并删除或修改以前的文档字段在索尔杰? 还是我在架构中遗漏了任何配置? 谢谢
I want to edit document filed in solr,for example edit the author name,so i use the following code in solrj:
params.set("literal.author","anaconda")
but the author multivalued="true" in schema and because of that "anaconde" is not replace with it's previous name and add to the end of the author name,also if i ommit the multivalued field or set it to false the bad request exception happen in re-indexing file with new author field,how can i solve this problem and delete or modify the previous document field in solrj?
or does it any config i miss in schema?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我知道的唯一选择是使用 solrj 将完整文档(使用
&fl=*
参数的所有字段)查询到本地构造中,更新相应的字段,然后提交整个文档将文档返回给 Solr。The only option I know of would be to query the full document (all fields using
&fl=*
parameter) into a local construct with solrj, update the appropriate field(s) and them submit the entire document back to Solr.不,无法更新 Solr 中文档的特定字段,也无法通过它的任何客户端 api。
编辑:- 使用 Solr 4.0 可以部分更新具有某些字段的文档。
Nope there is no way to update specific field for an document in Solr, nor through any of its Client apis.
EDIT :- With Solr 4.0 it it possible to Partially update the documents with certain fields.
这篇帖子应该是您问题的正确答案(如果您使用的是 SOLR 4.x)
This post should be the correct answer to your question (if you are using SOLR 4.x)
对于 Solr 4.0,您可以更新文档上的单个字段,但如果您担心的话,该版本是 ALPHA。
但是对于更新来说,我认为只能通过 CURL 来实现,我没有找到任何方法可以通过 solrj 更新 java 端文档上的单个字段。
For Solr 4.0 you are able to update a single field on a document, but that version is ALPHA, if you are concerned.
But for the update thingy, it is only possible by CURL I think, I didnt find any way to update a single field on a doc on java side by solrj.
您有两个选择:
如其他答案中所述,您可以查询原始文档,更新字段,然后重新保存,这将用新值覆盖原始文档。
您的另一个选择是安装 Solr 的夜间版本,其中 Yonik 添加了可更新文档的补丁。您应该关注 https://issues.apache.org/jira/browse/SOLR -139,因为这个补丁非常新并且仍在开发中。
You have two options:
As stated in other answers, you can query for the original document, update the field, and then re-save which will overwrite the original document with the new values.
Your other option is to install a nightly build of Solr, where Yonik has added a patch for updateable documents. You should keep an eye on https://issues.apache.org/jira/browse/SOLR-139 as this patch is pretty new and still being worked on.