How to
Creating parent-child relationships
The indexing technique for maintaining parent-child relationships between records when you migrate data to Algolia’s JSON format.
If your source data has parent-child relationships between records and you want to maintain those relationships when you migrate to Algolia’s JSON format, this guide outlines the recommended indexing process.
Use parent-child relationships when you want to:
- Filter on children
- Update parents without affecting children
- Index a tree-like data structure
- Model a one-to-many relationship.
Modeling the relationship in your JSON file
To model a parent-child relationship in the records of your Algolia JSON data:
- Create one record per child, and add a unique reference to their parent as a key-value pair (
parentID
in the example) - Don’t create records for parents.
Dataset
json
Implementation notes
Since:
- You don’t have any parent records: you can only query children.
- A parent may have many children: use Algolia’s distinct feature to retrieve the most relevant child per parent (
parentID
in the preceding example).
Was this page helpful?