About primary-key attributes

A primary key is required in order to add, delete, or modify a record in the data store.

Each record in the data store is uniquely identified by a unique record identifier, which is a combination of a unique standard attribute and a value that appears only on that record (that is, no other record in the data set has the same key-value pair that is on this record). This unique standard attribute is called a primary-key attribute. The primary-key attribute and a value assigned to a record becomes the primary key of the record. Every record added to the data store must have a primary key.

The primary-key attribute type can be of any supported Dgraph property types. The name of the primary-key attribute must be in an NCName format.

Typically, you would use the mdex:string or mdex:int types for the primary-key attribute. When you use the primaryKey element to create the primary-key attribute, the resulting property type will be whatever type is specified by the record's primary key (which is in the addAssignments element). Note that the primary-key attribute is created only if it is assigned to a record.

The PDR (Property Description Record) for the primary-key attribute must have this property set:

For example, assume that the name of a primary-key attribute is partID. The value partID=P123 can be assigned to only one record in the data set and is the primary key for that record. No other record can have this key-value pair. As a result, this primary key uniquely identifies this record in the data set.

Note: Keep in mind that multiple primary key attributes can exist in the data store. Each record must have one (and only one) primary key. The Data Ingest Web Service will throw an error if you attempt to add a second primary-key attribute to a record that already has a primary key.

Using the primaryKey element

When adding a record, the primary-key attribute (that will be assigned on the record) must already exist in the data store or (if it does not exist) must be specified in the add-records request with the primaryKey element. This example shows the primaryKeys section of a request:
<ingest:ingestRecords 
      xmlns:ingest="http://www.endeca.com/MDEX/ingest/1/0" 
      xmlns:mdex="http://www.endeca.com/MDEX/XQuery/2009/09">
   <ingest:primaryKeys>
      <ingest:primaryKey name="partID"/>
   </ingest:primaryKeys>
   <ingest:addAssignments>
      <mdex:record>
         <partID type="mdex:string">P123</partID>
         <modelNum type="mdex:int">2562</modelNum>
      </mdex:record>
   </ingest:addAssignments>
</ingest:ingestRecords>

The example creates one primary-key attribute (partID), which is used to create a record whose primary key is partID=P123.

Default values for primary-key attributes

If you specify a non-existent attribute as the primary key, the standard attribute is automatically created by the Data Ingest Web Service. The PDR for the attribute will use the system default settings, which (unless they have been changed by the data developer) are:
PDR property Default setting
mdex-property_Key Set to the name specified in the request.
mdex-property_Type Set to the Dgraph property type specified in the request. If no property type was specified, defaults to an mdex:string type.
mdex-property_IsPropertyValueSearchable true (the attribute will be enabled for value search)
mdex-property_IsSingleAssign true (a record may have at most one value for the attribute)
mdex-property_IsTextSearchable false (the attribute will be disabled for record search)
mdex-property_IsUnique true (a value may be assigned to at most one record)
mdex-property_TextSearchAllowsWildcards false (wildcard search is disabled for this attribute)
system-navigation_Select single (allows selecting only one refinement from this attribute)
system-navigation_ShowRecordCounts true (record counts will be shown for a refinement)
system-navigation_Sorting record-count (refinements are sorted in descending order, by the number of records available for each refinement)