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
- Select Models in the sidebar.
- Select the model.
- Select Filters & search.
Add a combined filter
- In Combined filters, select Add combined filter. You can add up to 4.
- In the new row, select + field and pick a field. Add up to 4 fields.
- Optional: select the button with the tooltip Toggle direction on a field to sort that field descending.
- Optional: in the name field, enter a name. Without a name, Morphic joins the field names with
_. - 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
- In Unique values, select Add rule.
- In the new rule, select + field and pick a field. Repeat to add each field that must be unique together.
- In the scope list, select across the site or within the same parent.
Save the model
- 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
| Badge | Meaning |
|---|---|
| Ready | Built and usable. |
| Building… | Filling in the background. |
| Failed | The 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
- Go to the Filters & search tab of the model.
- On the row with the Failed badge, read the error text.
- 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, andretryset to true.