Guides
/
Sending and managing data
/
Prepare your records for indexing
Jan. 19, 2023
Creating parent-child relationships
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
Copy
1
2
3
4
5
6
7
8
9
10
11
12
[
{
"parentID":"ABC",
"parentName":"Parent",
"name":"Child One"
},
{
"parentID":"ABC",
"parentName":"Parent",
"name":"Child Two"
}
]
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).
Did you find this page helpful?