【问题标题】:Apache Solr - Document is missing mandatory uniqueKey field: idApache Solr - 文档缺少必填的 uniqueKey 字段:id
【发布时间】:2018-05-22 17:22:05
【问题描述】:

我正在使用 Solr7.1(SolrCloud 模式),我不需要强制执行文档唯一性。 因此,我将架构中的 id 字段(指定为唯一键)标记为 required="false"

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

<uniqueKey>id</uniqueKey>

我正在尝试使用 solr Admin UI 对一些文档进行索引,但我正在尝试不指定 'id' 字段。

{ "cat": "books", "name": "JayStore" } 我期待它能够成功建立索引,但 solr 抛出错误,提示“缺少强制唯一键字段 id”

谁能指导我做错了什么。

【问题讨论】:

  • 请发布完整的错误日志,因为这可能会提供有关正在发生的事情的确切信息
  • @suvartheec 这是来自“更新” REST API ` { “responseHeader”:{ “status”:400, “QTime”:2}, “error”:{ “metadata”:[ "error-class","org.apache.solr.common.SolrException", "root-error-class","org.apache.solr.common.SolrException"], "msg":"文档缺少必填的 uniqueKey 字段: id", "code":400}} ` 这是管理 UI 上显示的消息:Document is missing mandatory uniqueKey field: id

标签: indexing solr schema unique-key


【解决方案1】:

uniqueKey 字段是 Solr 内部对某些功能所必需的,例如使用 cursorMark - 这意味着定义为 uniqueKey 的字段是必需的。默认情况下,它还用于 SolrCloud 内部的路由等(IIRC),因此如果它不存在,Solr 将无法正确分片您的文档。在架构中将其设置为不需要不会放松该要求。

但您可以通过定义 UUID 字段和 using a UUID Update Processor as described in the old wiki 来解决此问题。这将在您为每个文档编制索引时为其生成唯一的 UUID,这意味着默认情况下,每个文档都将获得一个唯一的标识符。

UUID 是 Universal Unique IDentifier 的缩写。 UUID 标准 RFC-4122 包括几种具有不同输入格式的 UUID。 Solr 1.4 中有一个 UUID 字段类型(称为 UUIDField),它实现了版本 4。字段在 schema.xml 文件中定义:

<fieldType name="uuid" class="solr.UUIDField" indexed="true" />

在 Solr 4 中,此字段必须通过 solr.UUIDUpdateProcessorFactory 填充。

&lt;field name="id" type="uuid" indexed="true" stored="true" required="true"/&gt; <updateRequestProcessorChain name="uuid"> <processor class="solr.UUIDUpdateProcessorFactory"> <str name="fieldName">id</str> </processor> <processor class="solr.RunUpdateProcessorFactory" / </updateRequestProcessorChain>

【讨论】:

  • 有道理。但是关于&lt;uniqueKey&gt; xml 元素的文档有些混乱。如下所示:&lt;!-- Field to use to determine and enforce document uniqueness. Unless this field is marked with required="false", it will be a required field --&gt; &lt;uniqueKey&gt;id&lt;/uniqueKey&gt;
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多