可以在 Solr 4 中更新 uniqueKey 吗? [英] It is possible to update uniqueKey in Solr 4?

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

问题描述

我的 uniqueKey 定义为:

My uniqueKey is defined as:

<field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" /> 
<uniqueKey>id</uniqueKey>

我将几个文档及其对应的id"字段加载到 Solr 中,我现在需要的是更新id"值,这可能吗?

I load several docs into Solr with its corresponding "id" field, what i need now is UPDATE "id" value, It is possible?

当我尝试这样做时,我收到此错误:

When I try to do that I get this error:

Document contains multiple values for uniqueKey field

我使用的是 Apache Solr 4.3.0

I am using Apache Solr 4.3.0

推荐答案

这不是直接可能的.在我介绍如何间接地做到这一点之前,我需要解释一些事情.

It's not directly possible. Before I get into how you can do it indirectly, I need to explain a couple of things.

uniqueKey 字段中的值是 Solr 处理文档更新/替换的方式.当您发送文档进行索引时,如果已经存在具有相同 uniqueKey 值的现有文档,Solr 将在索引新文档之前删除其自己的副本.

The value in the uniqueKey field is how Solr handles document updating/replacing. When you send a document in for indexing, if an existing document with the same uniqueKey value already exists, Solr will delete its own copy before indexing the new one.

原子更新功能略有不同.它允许更新添加、更改或删除文档中除 uniqueKey 字段之外的任何字段 - 因为这是 Solr 可以识别文档的方式.

The atomic update functionality is slightly different. It lets an update add, change, or remove any field in the document except the uniqueKey field - because that's the way that Solr can identify the document.

您需要做的基本上是用旧文档中的所有数据索引一个新文档,然后删除旧文档.如果文档中的所有字段都可用于索引过程,那么您可以在删除旧文档之前或之后索引新文档.否则,您可以从 Solr 中查询现有文档,创建一个新文档并为其建立索引,然后删除旧文档.

What you need to do is basically index a new document with all the data from the old document, and delete the old document. If all the fields in the document are available to the indexing process, then you can just index the new document, either before or after deleting the old one. Otherwise, you can query the existing doc out of Solr, make a new one and index it, and then delete the old one.

为了使用现有的 Solr 文档来索引新的文档,必须存储所有字段,除非它们是 copyField 目标,在这种情况下不能存储它们.原子更新(上面讨论过)具有相同的要求.如果这些字段中的一个或多个未存储,则搜索结果将不包含该字段并且数据将丢失.

In order to use the existing Solr document to index a new one, all fields must be stored, unless they are copyField destinations, in which case they must NOT be stored. Atomic updates (discussed above) have the same requirement. If one or more of these fields is not stored, then the search result will not contain that field and the data will be lost.

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

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