Solr Composite来自模式中现有字段的唯一键 [英] Solr Composite Unique key from existing fields in schema
问题描述
我在solr中有一个名为 LocationIndex
的索引,其字段如下:
I have an index named LocationIndex
in solr with fields as follows:
<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
...如下所示:
But now I want to change schema so that unique key must be composite of two already present fields solr_id
and solr_ver
... something as follows:
<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>
搜索后我发现可以通过在架构中添加以下内容:(ref:来自模式中现有字段的复合唯一键)
After searching I found that it's possible by adding following to schema: (ref: 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>
所以我改变了架构,最后看起来像:
So I changed schema and finally it looks like:
<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>
但是在添加文档时它会给我错误:
But while adding a document it's giving me error:
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
我没有得到架构中需要的更改才能按需运行?
I'm not getting what changes in schema are required to work as desired?
在我添加的文档中,它包含字段 solr_ver
和 solr_id
。如何以及在何处(solr)通过组合这些字段来创建 id
字段,例如 solr_ver-solr_id
?
In a document I add, it contain fields solr_ver
and solr_id
. How and where it'll (solr) create id
field by combining both these field something like solr_ver-solr_id
?
编辑:
这个链接给出了如何引用这个链。我无法理解如何在架构中使用它?我应该在哪里进行更改?
At this link It's given how refer to this chain. Bu I'm unable to understand how would it be used in schema? And where should I make changes?
推荐答案
所以看起来你已经适当地定义了updateRequestProcessorChain,它应该可以工作。但是,您需要将其添加到solrconfig.xml文件而不是schema.xml。您提供的附加链接向您展示了如何修改solrconfig.xml文件并将定义的updateRequestProcessorChain添加到solr实例的当前 / update
请求处理程序。
So it looks like you have your updateRequestProcessorChain defined appropriately and it should work. However, you need to add this to the solrconfig.xml file and not the schema.xml. The additional link you provided shows you how to modify your solrconfig.xml file and add your defined updateRequestProcessorChain to the current /update
request handler for your solr instance.
因此,请执行以下操作:
So find do the following:
- 移动
< updateRequestProcessorChain>
到你的solrconfig.xml文件。 -
更新
< requestHandler name =/ updateclass =solr。您的solrconfig.xml文件中的UpdateRequestHandler>
条目并对其进行修改,使其如下所示:
- Move your
<updateRequestProcessorChain>
to your solrconfig.xml file. Update the
<requestHandler name="/update" class="solr.UpdateRequestHandler">
entry in your solrconfig.xml file and modify it so it looks like the following:
<requestHandler name="/update" class="solr.UpdateRequestHandler">
<lst name="defaults">
<str name="update.chain">composite-id</str>
</lst>
</requestHandler>
这应该执行你定义的更新链和将新文档添加到索引时填充id字段。
This should then execute your defined update chain and populate the id field when new documents are added to the index.
这篇关于Solr Composite来自模式中现有字段的唯一键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!