Indexes

The Indexes field allows you to define multiple indexes for a given type. By adding this field, you can enable the use of several indexes as well as set uniqueness constraints across multiple fields. This functionality is especially useful for applications that require efficient data management through multiple indexes.

For instance, consider the definition of the titleAndSku index as follows:

<span><span style="color: var(--shiki-color-text)">Product: commonType.#CommonType </span><span style="color: var(--shiki-token-keyword)">&amp;</span><span style="color: var(--shiki-color-text)"> {</span></span>
<span><span style="color: var(--shiki-color-text)">	Name:        </span><span style="color: var(--shiki-color-text)">&quot;</span><span style="color: var(--shiki-token-string-expression)">Product</span><span style="color: var(--shiki-color-text)">&quot;</span></span>
<span><span style="color: var(--shiki-color-text)">	Description: </span><span style="color: var(--shiki-color-text)">&quot;</span><span style="color: var(--shiki-token-string-expression)">Product model</span><span style="color: var(--shiki-color-text)">&quot;</span></span>
<span><span style="color: var(--shiki-color-text)">	Indexes: {</span></span>
<span><span style="color: var(--shiki-color-text)">		titleAndSku: {</span></span>
<span><span style="color: var(--shiki-color-text)">			FieldNames: [</span></span>
<span><span style="color: var(--shiki-color-text)">				</span><span style="color: var(--shiki-color-text)">&quot;</span><span style="color: var(--shiki-token-string-expression)">title</span><span style="color: var(--shiki-color-text)">&quot;</span><span style="color: var(--shiki-token-punctuation)">,</span></span>
<span><span style="color: var(--shiki-color-text)">				</span><span style="color: var(--shiki-color-text)">&quot;</span><span style="color: var(--shiki-token-string-expression)">sku</span><span style="color: var(--shiki-color-text)">&quot;</span><span style="color: var(--shiki-token-punctuation)">,</span></span>
<span><span style="color: var(--shiki-color-text)">			]</span></span>
<span><span style="color: var(--shiki-color-text)">			Unique: </span><span style="color: var(--shiki-token-constant)">true</span></span>
<span><span style="color: var(--shiki-color-text)">		}</span></span>
<span><span style="color: var(--shiki-color-text)">	}</span></span>
<span><span style="color: var(--shiki-color-text)">}</span></span>
<span></span>

Within the Indexes configuration, you can specify the name of a composite index key using FieldNames, which identifies the fields to be included in the index. In the example provided, we’ve named the index titleAndSku, but this name is flexible and can be customized as needed.

Furthermore, the Unique attribute specifies the constraint for multiple fields to be unique.
Here, it signifies that each title and sku pairing must be distinct within the Product type, thereby preventing duplicate entries in the dataset.

Caveat: Enum type is not supported for the multiple indexes field.