Help topics

Add indexes and unique rules

Add combined filters and unique rules to a model so that lists filter quickly and each value is used once.

Before you start

  • You need the administrator role. Only administrators can change models.
  • You need a model with a field that can be filtered. Turn on Filter by this field in a field to make it filterable.

Steps

  1. Select Models in the sidebar.
  2. Select the model.
  3. Select Filters & search.

Add a combined filter

  1. In Combined filters, select Add combined filter. You can add up to 4.
  2. In the new row, select + field and pick a field. Add up to 4 fields.
  3. Optional: select the button with the tooltip Toggle direction on a field to sort that field descending.
  4. Optional: in the name field, enter a name. Without a name, Morphic joins the field names with _.
  5. Optional: in the field with the placeholder Only when, e.g. {"status":["published"]}, enter a JSON condition. Entries that do not match are left out of the index.

Add a unique rule

  1. In Unique values, select Add rule.
  2. In the new rule, select + field and pick a field. Repeat to add each field that must be unique together.
  3. In the scope list, select across the site or within the same parent.

Save the model

  1. Select Save changes.

Result

Each combined filter and unique rule shows a status badge. Ready means the index can answer queries. A new index or rule shows Building… until its entries are filled in.

Index status

BadgeMeaning
ReadyBuilt and usable.
Building…Filling in the background.
FailedThe build stopped. The error text shows next to the badge.

Morphic fills indexes and unique rules in the background after you save a model. The model header shows N building while a build runs.

To check every build, open Settings > General and look at the Background work row. It shows Idle when no build runs.

Retry a failed build

  1. Go to the Filters & search tab of the model.
  2. On the row with the Failed badge, read the error text.
  3. Select Retry. Morphic shows Rebuilding, and the row returns to Building….

Morphic clears the index and fills it again.

Limits

  • Up to 8 single-field filters.
  • Up to 4 combined filters, each with 2 to 4 fields.
  • A save is refused when it would write more than 64 keys. Each index and unique rule adds to the count. The editor shows Each save does N small writes (limit 64).
  • Secret fields cannot be indexed or unique.

Errors

  • Only when must be JSON like {"status": ["published"]}: The JSON in Only when does not parse. The value is not saved.
  • a composite index has 2 to 4 fields: A combined filter has fewer than 2 or more than 4 fields.
  • index name NAME is used twice: Two combined filters have the same name.
  • another MODEL already has this FIELD: An entry repeats a value that a unique rule already holds. For a rule with several fields, the names are joined with + .
  • index_building: While an index is building, a read that needs it fails with code index_building, HTTP 503, and retry set to true.