Subscribe

Close

Thank you for visiting!

Please consider subscribing to the RSS feed or following me on Twitter.

Solr Indexing And The Unique Key Field

If you encounter problems with Solr indexing and inconsistencies in the actual indexing - you might have a problem with the Solr unique key field.

If you index items that may have the same id, and this id is used as the unique key in Solr - then you have a problem. Items with the same id's will simply not be tolerated in the Solr index, thus the latter item overwrites the former when indexing. Of course, this is a default and correct behaviour from Solr.

However - this is easy to solve. You just have to use the UUID (Universal Unique Identifier) field type in Solr.

In schema.config in your Solr conf folder (normally C:/solr/conf or similar), add the UUID type, like this:

<fieldType name="uuid" class="solr.UUIDField" indexed="true" />

Then, add a field of this type (still in schema.config):

 <field name="uid" type="uuid" indexed="true" stored="true"
	default="NEW" />

Finally, make sure to point out this field as the unique key, in schema.config:

<uniqueKey>uid</uniqueKey>

All done! Now all your indexed items will have a unique ID.

Here's more documentation on Solr and the UniqueKey field.

Comments

Hi,
Thanks for the post. But when I tried this I am getting configuration error that QueryElevationComponent requires the schema to have a uniqueKeyField implemented using StrField .I am using solr 1.4

Please help

at the moment QueryElevationComponent requires a string unique key. This limitation is documented in the Solr wiki.

see : http://wiki.apache.org/solr/QueryElevationComponent#elevate.xml

Is it possible to make a field unique key without it being a 'uuid' and just text_general?

Juzer Ali: As long as it's truly unique it should work, I think.

As your tutorial

Solr apach exception error: uniqueKey field (null) can not be configured with a default value (NEW)

same error with me like Panpic

To the top