简体   繁体   English

Solr / SolrNet:如何给定文档唯一ID的文档进行更新?

[英]Solr/SolrNet: How can I update a document given a document unique ID?

I need to update few fields of each document in Solr index separately from the main indexing process. 我需要与主要索引编制过程分开分别更新Solr索引中每个文档的几个字段。 According to documentation "Create" and "Update" are mapped onto the "Add()" function. 根据文档,“创建”和“更新”被映射到“ Add()”函数上。 http://code.google.com/p/solrnet/wiki/CRUD http://code.google.com/p/solrnet/wiki/CRUD

So if I add a document which already exist, will it replace the entire document or just the fields that I have specified? 因此,如果我添加一个已经存在的文档,它将替换整个文档还是仅替换我指定的字段?

If it'll replace the entire document then the only way that I can think of in order to update is to search the document by unique id, update the document object and then "Add" it again. 如果它将替换整个文档,那么我想进行更新的唯一方法就是通过唯一的ID搜索文档,更新文档对象,然后再次“添加”它。 This doesn't sound feasible because of the frequency of update ops required. 由于需要更新操作的频率,这听起来不可行。 Is there a better way to update? 有更好的更新方法吗?

Thanks! 谢谢!

Unfortunately, Solr does not currently support updating individual fields for a given document in the index. 不幸的是,Solr当前不支持为索引中给定文档更新单个字段。 The later scenario you describe of retrieving the entire document contents (either from Solr or the original source) and then resending the document (adding via SolrNet) is the only way to update documents in Solr. 您描述的稍后的场景是检索整个文档内容(从Solr或原始来源)然后重新发送文档(通过SolrNet添加),这是在Solr中更新文档的唯一方法。

Please see the previous question: Update specific field on Solr index for more details about Solr not supporting individual field updates and an open JIRA issue for adding this support to Solr. 请参阅上一个问题: Solr索引上的“更新特定字段”,以获取有关Solr不支持单个字段更新的更多详细信息,以及有关向Solr添加此支持的JIRA问题。

Partial updating of documents is now supported in the newer versions of Solr, for example 4.10 does pretty well. Solr的较新版本现在支持文档的部分更新,例如4.10很好。 Please look at the following page for more information: https://cwiki.apache.org/confluence/display/solr/Updating+Parts+of+Documents 请查看以下页面以获取更多信息: https : //cwiki.apache.org/confluence/display/solr/Updating+Parts+of+Documents

The only detail is that you need to declare your fields as stored=true to allow for partial updates. 唯一的细节是您需要将字段声明为stored = true,以允许部分更新。

I also show how to do it in this training: http://www.pluralsight.com/courses/enterprise-search-using-apache-solr 我还将在此培训中展示如何做: http : //www.pluralsight.com/courses/enterprise-search-using-apache-solr

In this specific module: Content: Schemas, Documents and Indexing 在此特定模块中:内容:架构,文档和索引

If you need to frequently update a lot of documents in SOLR, you might need to rethink your entire solution. 如果您需要经常更新SOLR中的许多文档,则可能需要重新考虑整个解决方案。 In typical solutions that use SOLR and require lots of frequent updates to documents, the way it is usually done is that the documents reside in some SQL or NoSQL database, and they are modified there. 在使用SOLR且需要大量频繁更新文档的典型解决方案中,通常的做法是将文档驻留在某些SQL或NoSQL数据库中,并在其中进行修改。 Then you use DIH or something similar to bulk update the SOLR index from the database, possibly just dropping the index and re-indexing all content. 然后,您可以使用DIH或类似的方法从数据库中批量更新SOLR索引,可能只是删除索引并重新索引所有内容。 SOLR can index documents very quickly so that is typically not a problem. SOLR可以非常快速地为文档建立索引,因此这通常不是问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM