Guides / Sending and managing data / Format and structure your data

Creating and Using Nested Attributes

What are nested attributes?

Nested attributes are a way of applying sub-categories to your attributes. For instance, instead of having a single searchable attribute price, you may set up some sub-categories: price.net, price.gross, price.margin (note the use of ‘dot notation’ here to separate the parent attribute from its child).

How to create nested attributes

You can create nested attributes by adding a JSON object to your records when you send your records to Algolia. For example:

1
2
3
4
5
6
7
{
  "title": "Bread",
  "price": {
    "net": 1.99,
    "gross": 1.75
  }
}

Where you can use nested attributes

You can use nested attributes wherever you might use a regular attribute, such as searchableAttributes and attributesForFaceting. Just make sure you use the appropriate dot notation (for example, authors.mainAuthor) to refer to them.

You can’t add nested attributes to searchableAttributes in the dashboard, you must use the setSettings method on an API client to define them.

There are no limitations on the number of nested attributes apart from the default restrictions on record size. There are also no limits on the depth of your nesting: you could use something like price.net.england.yorkshire.

Did you find this page helpful?