> ## Documentation Index
> Fetch the complete documentation index at: https://algolia.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create nested attributes

> Learn about nested attributes, and when to use them.

export const Records = () => <Tooltip tip="A record is a searchable object in an Algolia index. Each record consists of named attributes." cta="Algolia records" href="/doc/guides/sending-and-managing-data/prepare-your-data#algolia-records">
    records
  </Tooltip>;

With nested attributes, you can add subcategories to your attributes.
For example, instead of having a single attribute `price`,
you can set up different prices as subcategories: `price.net`, `price.gross`, `price.margin`.
To refer to nested attributes, separate parent and child attribute with a `.`.

To create nested attributes,
add them as nested JSON objects to your <Records />.
For example:

```json JSON icon=braces theme={"system"}
[
  {
    "country": "CA",
    // price is a nested attribute
    "price": {
      "net": 2.30,
      "gross": 2.62
    }
  },
  {
    "country": "US",
    // price is a nested attribute
    "price": {
      "net": 1.99,
      "gross": 1.75
    }
  }
]
```

## Example: filtering nested attributes

If you want to filter a search using nested attributes,
use the [`filters`](/doc/api-reference/api-parameters/filters) parameter in your search request
and separate the parent and child attribute by a `.`.
For example, with the JavaScript API client:

<CodeGroup>
  ```cs C# theme={"system"}
  var response = await client.SearchSingleIndexAsync<Hit>(
    "INDEX_NAME",
    new SearchParams(new SearchParamsObject { Filters = "country:US AND price.gross < 2.0" })
  );
  ```

  ```dart Dart theme={"system"}
  final response = await client.searchSingleIndex(
    indexName: "INDEX_NAME",
    searchParams: SearchParamsObject(
      filters: "country:US AND price.gross < 2.0",
    ),
  );
  ```

  ```go Go theme={"system"}
  response, err := client.SearchSingleIndex(client.NewApiSearchSingleIndexRequest(
    "INDEX_NAME").WithSearchParams(search.SearchParamsObjectAsSearchParams(
    search.NewEmptySearchParamsObject().SetFilters("country:US AND price.gross < 2.0"))))
  if err != nil {
    // handle the eventual error
    panic(err)
  }
  ```

  ```java Java theme={"system"}
  SearchResponse response = client.searchSingleIndex(
    "INDEX_NAME",
    new SearchParamsObject().setFilters("country:US AND price.gross < 2.0"),
    Hit.class
  );
  ```

  ```js JavaScript theme={"system"}
  const response = await client.searchSingleIndex({
    indexName: 'indexName',
    searchParams: { filters: 'country:US AND price.gross < 2.0' },
  });
  ```

  ```kotlin Kotlin theme={"system"}
  var response =
    client.searchSingleIndex(
      indexName = "INDEX_NAME",
      searchParams = SearchParamsObject(filters = "country:US AND price.gross < 2.0"),
    )
  ```

  ```php PHP theme={"system"}
  $response = $client->searchSingleIndex(
      'INDEX_NAME',
      ['filters' => 'country:US AND price.gross < 2.0',
      ],
  );
  ```

  ```python Python theme={"system"}
  response = client.search_single_index(
      index_name="INDEX_NAME",
      search_params={
          "filters": "country:US AND price.gross < 2.0",
      },
  )
  ```

  ```ruby Ruby theme={"system"}
  response = client.search_single_index(
    "INDEX_NAME",
    Algolia::Search::SearchParamsObject.new(filters: "country:US AND price.gross < 2.0")
  )
  ```

  ```scala Scala theme={"system"}
  val response = Await.result(
    client.searchSingleIndex(
      indexName = "INDEX_NAME",
      searchParams = Some(
        SearchParamsObject(
          filters = Some("country:US AND price.gross < 2.0")
        )
      )
    ),
    Duration(100, "sec")
  )
  ```

  ```swift Swift theme={"system"}
  let response: SearchResponse<Hit> = try await client.searchSingleIndex(
      indexName: "INDEX_NAME",
      searchParams: SearchSearchParams
          .searchSearchParamsObject(SearchSearchParamsObject(filters: "country:US AND price.gross < 2.0"))
  )
  ```
</CodeGroup>

## Where you can use nested attributes

You can use nested attributes wherever you might use a regular attribute, such as [`searchableAttributes`](/doc/api-reference/api-parameters/searchableAttributes) and
[`attributesForFaceting`](/doc/api-reference/api-parameters/attributesForFaceting).
Just make sure you use the appropriate dot notation such as `price.country` to refer to them.

There's no limit on the number of nested attributes apart from [the default restrictions on record size](https://support.algolia.com/hc/en-us/articles/4406981897617-Is-there-a-size-limit-for-my-index-records).
The maximum nesting depth is 256 levels, which is more than enough for most use cases.
For example, you could use something like `price.net.us.ca`.
