我在 solr 中有一个名为 LocationIndex
的索引,其字段如下:
<fields>
<field name="solr_id" type="string" stored="true" required="true" indexed="true"/>
<field name="solr_ver" type="string" stored="true" required="true" indexed="true" default="0000"/>
// and some more fields
</fields>
<uniqueKey>solr_id</uniqueKey>
但现在我想更改架构,以便唯一键必须由两个已经存在的字段 solr_id
和 solr_ver
组成......如下所示:
<fields>
<field name="solr_id" type="string" stored="true" required="true" indexed="true"/>
<field name="solr_ver" type="string" stored="true" required="true" indexed="true" default="0000"/>
<field name="composite-id" type="string" stored="true" required="true" indexed="true"/>
// and some more fields
</fields>
<uniqueKey>solr_ver-solr_id</uniqueKey>
搜索后我发现可以通过向模式添加以下内容来实现:(引用:Solr Composite Unique key from existing fields in schema)
<updateRequestProcessorChain name="composite-id">
<processor class="solr.CloneFieldUpdateProcessorFactory">
<str name="source">docid_s</str>
<str name="source">userid_s</str>
<str name="dest">id</str>
</processor>
<processor class="solr.ConcatFieldUpdateProcessorFactory">
<str name="fieldName">id</str>
<str name="delimiter">--</str>
</processor>
<processor class="solr.LogUpdateProcessorFactory" />
<processor class="solr.RunUpdateProcessorFactory" />
</updateRequestProcessorChain>
所以我改变了架构,最后它看起来像:
<updateRequestProcessorChain name="composite-id">
<processor class="solr.CloneFieldUpdateProcessorFactory">
<str name="source">solr_ver</str>
<str name="source">solr_id</str>
<str name="dest">id</str>
</processor>
<processor class="solr.ConcatFieldUpdateProcessorFactory">
<str name="fieldName">id</str>
<str name="delimiter">-</str>
</processor>
<processor class="solr.LogUpdateProcessorFactory" />
<processor class="solr.RunUpdateProcessorFactory" />
</updateRequestProcessorChain>
<fields>
<field name="solr_id" type="string" stored="true" required="true" indexed="true"/>
<field name="solr_ver" type="string" stored="true" required="true" indexed="true" default="0000"/>
<field name="id" type="string" stored="true" required="true" indexed="true"/>
// and some more fields
</fields>
<uniqueKey>id</uniqueKey>
但是在添加文档时出现错误:
org.apache.solr.client.solrj.SolrServerException: Server at http://localhost:8983/solr/LocationIndex returned non ok status:400, message:Document [null] missing required field: id
我不知道需要对架构进行哪些更改才能按预期工作?
在我添加的文档中,它包含字段 solr_ver
和 solr_id
。它将如何以及在何处 (solr) 通过组合这两个字段来创建 id
字段,例如 solr_ver-solr_id
?
编辑:
在 this link它给出了如何引用这个链。 Bu 我无法理解它将如何在模式中使用?我应该在哪里进行更改?
最佳答案
所以看起来您已经正确定义了 updateRequestProcessorChain,它应该可以工作。但是,您需要将其添加到 solrconfig.xml 文件而不是 schema.xml。您提供的附加链接向您展示了如何修改 solrconfig.xml 文件并将您定义的 updateRequestProcessorChain 添加到当前 /update
您的 solr 实例的请求处理程序。
所以 find 执行以下操作:
- 移动您的
<updateRequestProcessorChain>
到您的 solrconfig.xml 文件。 更新
<requestHandler name="/update" class="solr.UpdateRequestHandler">
在您的 solrconfig.xml 文件中输入并修改它,使其如下所示:<requestHandler name="/update" class="solr.UpdateRequestHandler"> <lst name="defaults"> <str name="update.chain">composite-id</str> </lst> </requestHandler>
这应该会执行您定义的更新链,并在新文档添加到索引时填充 id 字段。
关于java - 架构中现有字段的 Solr 复合唯一键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17806821/