movies index can reference actors by ID. When you search for movies, Meilisearch automatically replaces the actor IDs with full actor documents from the actors index. This approach also works with multi-search when querying across related indexes.
Step 1: Enable the experimental feature
Foreign keys must be activated through the experimental features endpoint before you can use them:Step 2: Create your related index
Add documents to the index you want to reference. In this example, create anactors index with actor data:
Step 3: Configure foreign keys in the main index
Use the settings endpoint to define which fields contain foreign references and which index they point to:actors field in the movies index contains IDs that reference documents in the actors index.
Step 4: Add documents with foreign IDs
Add documents to your main index. Use arrays of IDs for the foreign key field:Step 5: Search and see hydrated results
When you search themovies index, Meilisearch automatically replaces foreign IDs with full documents from the referenced index:
Limitations
- Experimental: This feature may change or be removed in future versions.
- No remote sharding: Foreign keys are not supported in environments using remote sharding.
- One direction: Hydration works from the main index to the referenced index. The referenced index does not automatically link back.
Next steps
Foreign keys settings API
Full API reference for foreign key settings
Experimental features API
Enable and manage experimental features
Indexing overview
Learn more about how indexing works in Meilisearch