模式中现有字段的 Solr 复合唯一键 [英] Solr Composite Unique key from existing fields in schema

查看:23
本文介绍了模式中现有字段的 Solr 复合唯一键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 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_idsolr_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>

搜索后我发现可以通过向架构添加以下内容:(参考:Solr Composite Unique key from模式中的现有字段)

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_versolr_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:

  1. 将您的 移动到您的 solrconfig.xml 文件中.
  2. 更新 solrconfig.xml 文件中的 <requestHandler name="/update" class="solr.UpdateRequestHandler"> 条目并修改它,使其看起来如下所示:

  1. Move your <updateRequestProcessorChain> to your solrconfig.xml file.
  2. 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 复合唯一键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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