Skip to main content
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.

Model relationships 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
[
   {
      "parentID":"ABC",
      "parentName":"Parent",
      "name":"Child One"
   },
   {
      "parentID":"ABC",
      "parentName":"Parent",
      "name":"Child Two"
   }
]

Implementation notes

Since this structure doesn’t have parent records, you can only query children. To retrieve the most relevant child per parent (parentID in the preceding example), use Algolia’s distinct feature. For more information, see:
⌘I