solr 6.2.1 uniqueField not work

2019-06-09 08:06发布

问题:

i install solr 6.2.1 and in schema define a uniqueField:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Solr managed schema - automatically generated - DO NOT EDIT -->
<schema name="ps_product" version="1.5">
  <fieldType name="int" class="solr.TrieIntField" positionIncrementGap="0" precisionStep="0"/>
  <fieldType name="long" class="solr.TrieLongField" positionIncrementGap="0" precisionStep="0"/>
  <fieldType name="string" class="solr.TextField" omitNorms="true" sortMissingLast="true"/>
  <fieldType name="uuid" class="solr.UUIDField" indexed="true"/>

  <field name="_version_" type="long" multiValued="false" indexed="true" stored="true"/>
  <field name="id_product" type="uuid" default="NEW" indexed="true" stored="true"/>
  <uniqueKey>id_product</uniqueKey>
  <field name="name" type="string" indexed="true" stored="true"/>
  <field name="title" type="string" multiValued="false" indexed="true" required="true" stored="true"/>
</schema>

and my data-config like bellow:

<dataConfig>
    <dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/pressdb-local" user="sa" password="" />
    <document>
        <entity name="item" query="select * from ps_product as p inner join ps_product_lang as pl on pl.id_product=p.id_product where pl.id_lang=2"
                deltaQuery="select id from ps_product where date_upd > '${dataimporter.last_index_time}'">
            <field name="name" column="name"/>
            <field name="id_product" column="id_product"/>

            <entity name="comment"  
                    query="select title from ps_product_comment where id_product='${item.id_product}'"
                    deltaQuery="select id_product_comment from ps_product_comment where date_add > '${dataimporter.last_index_time}'"
                    parentDeltaQuery="select id_product from ps_product where id_product=${comment.id_product}">
                <field name="title" column="title" />
            </entity>

        </entity>
    </document>
</dataConfig>

but when i want to define a core in solr, give me error:

Error CREATEing SolrCore 'product': Unable to create core [product] Caused by: QueryElevationComponent requires the schema to have a uniqueKeyField.

please help me to solve this problem.

回答1:

Since Solr 4 and to support SolrCloud the uniqueKey field can no longer be populated using default=... you should remove it from the feld definition in schema.xml :

<field name="id_product" type="uuid" indexed="true" stored="true"/>

Update: As pointed out by MatsLindh, it seems you are using Solr in schemaless mode. Schema updates in this mode must be done via the Schema API, you should not edit the managed schema (<!-- Solr managed schema - automatically generated - DO NOT EDIT -->). To define id_product and uniqueKey field, use the API or revert to the classic schema mode.

To generate a uniqueKey to any document being added that does not already have a value in the specified field you can use UUIDUpdateProcessorFactory (cf. Update Request Processor). You will need to define an update processor chain in solrconfig.xml :

  <updateRequestProcessorChain name="uuid">
    <processor class="solr.UUIDUpdateProcessorFactory">
      <str name="fieldName">id_product</str>
    </processor>
    <processor class="solr.RunUpdateProcessorFactory" />
  </updateRequestProcessorChain>

Then specify the use of the processor chain via the request param update.chain in your request handler definition.



标签: apache solr