Juzer Ali
Juzer Ali

Reputation: 4167

Is it necessary for a unique key to be a uuid in Solr?

Can a unique key in Solr/Lucene schema be text_general instead? I have tried that but Solr doesn't overwrite the data, it simply adds another row hence duplicating the data.

I have commented out following from solrconfig.xml

<searchComponent name="elevator" class="solr.QueryElevationComponent" >
<!-- pick a fieldType to analyze queries -->
<str name="queryFieldType">string</str>
<str name="config-file">elevate.xml</str>
</searchComponent>

My schema.xml has

<uniqueKey>_id</uniqueKey>
<field name="_id" type="text_general" indexed="true" stored="true" default="NEW"/>

Any help would be greatly appreciated.

Upvotes: 0

Views: 1771

Answers (1)

javanna
javanna

Reputation: 60225

You can use whatever type you want for the uniqueKey field. As you can read from the documentation:

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.

It is not mandatory for a schema to have a uniqueKey field.

Note that if you have enabled the QueryElevationComponent in solrconfig.xml it requires the schema to have a uniqueKey of type StrField. It cannot be, for example, an int field.

What's important is that your uniqueKey field is unique, meaning that the same document has the same identifier. Only that way the replace if existing mechanism can work. Using an uuid field type you'd never replace a document because you would have a different id for each one, automatically.

Upvotes: 2

Related Questions