简体   繁体   中英

defining unique field in solr

I have a document in solr as

<entity name="Category" dataSource="ds1" pk="CategoryId"
    query="SELECT CategoryId, Description, ImageUrl FROM Category">
    <field column="CategoryId" name="CategoryId" />
    <entity name="PackCategory" pk="PackId, CategoryId"
     query="SELECT PackId FROM PackCategory WHERE CategoryId = ${Category.CategoryId}" >
     <entity name="Pack" pk="PackId"
      query="SELECT PackId, IsActive FROM Pack WHERE PackId = ${PackCategory.PackId}" >
      <field column="IsActive" name="IsActive" />
      <entity name="PartnerPackTrans" pk="PackId, PartnerId" transformer="TemplateTransformer">
       query="SELECT PartnerId FROM PartnerPackTrans WHERE PackId = ${Pack.PackId}" >
           <field column="PartnerId" name="PartnerId" />
      </entity>
</entity>
     </entity>
    </entity>
   </entity>

My unique id is a combination of (Cateogry.CategoryId, Pack.PackId, PartnerPackTrans.PartnerId). How can I define this is solr in schema.xml in unique field

Update After going through various post I added this my solr-config file

 <updateRequestProcessorChain name="id">
  <processor class="solr.CloneFieldUpdateProcessorFactory">
    <str name="source">CategoryId</str>
    <str name="source">PartnerId</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>

But I get this error in solr Document is missing mandatory uniqueKey field: id

i am refering this post Solr Composite Unique key from existing fields in schema

I am using solr version 5.3

In Solr, you can add a unique key :

The declaration can be used to inform Solr that there is a field in your index which should be unique for all documents. If a document is added that contains the same value for this field as an existing document, the old document will be deleted.

So, in your case, if your field is called unique , you have to add:

<uniqueKey>unique</uniqueKey>

UPDATE

To answer to your comment, in your schema.xml , you can create a new field:

<field name="unique" type="text_general" indexed="true" stored="true"  multiValued="true" />

After that, you can copy the fields that you want in your new field:

<copyField source="Cateogry.CategoryId" dest="unique"/>
<copyField source="Pack.PackId" dest="unique"/>
<copyField source="PartnerPackTrans.PartnerId" dest="unique"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM