Nested Objects and Arrays in Typesense
TLDR Robert seeks advice on managing nested objects in Typesense. Kishore Nallan informs of upcoming support for nested objects and provides a current workaround. Robert indicates interest in tracking this feature. Kishore Nallan provides a link to follow the issue.


Jun 23, 2022 (15 months ago)
Robert
10:36 AMI’m planning to use Typesense, but I have nested objects and object array in my structure. I read that flatting may help me, but in this case the indexing would be tricky, so I had another idea, to split my data into different collections. But in this case I would have trouble with the pagination of the results, or I wasn’t able to found any example for this. I made this example object to reflect on my real object:
{
"id": "random_id_1",
"name": "John Doe",
"read_history": [
{
"id": "random_book_id_1",
"name": "Harry Potter and the Philosopher's Stone",
"author": "J. K. Rowling"
},
{
"id": "random_book_id_2",
"name": "Ready Player One",
"author": "Ernest Cline"
}
],
"favorite_books": [
"random_book_id_2"
]
}
So here is an example, what I want to do. As result I want to display my readers and their favourite book names in a table, but I want to search in author names and book names as well.
In the different index idea, I planned create two indexes, first for general reader data (id, name, favorite_books) and the second would store the read history data with an extra owner_id field to connect the book document to the reader. The indexing was just fine in this case, if I ran a multi collection search I got the results in two different collections, but I want to paginate in the general reader data (and in optimal case, the book data should follow it, based on the shared id, like a SQL join) and not separately. Is there any chance I can do it with Typesense, or I have to merge (fetch and then aggregate) my objects manually?
Kishore Nallan
11:50 AMIn the mean time, you can convert the array of objects to simple plain arrays like this:
read_history.names: ["Harry Potter and the Philosopher's Stone", "Ready Player One"]
read_history.authors: ["J. K. Rowling", "Ernest Cline"]

Robert
11:52 AM
Jun 24, 2022 (15 months ago)
Robert
08:38 AMKishore Nallan
08:43 AMI will post on that issue when I have an early build available for testing.
Robert
08:43 AMTypesense
Indexed 2764 threads (79% resolved)
Similar Threads
Handling Nested Objects in Typesense
Darren queried about storing arrays of objects in Typesense. Kishore Nallan advised that Typesense doesn't support nesting but shared alternative reindexing methods. They added improved nesting support is planned for the future.
Discussing Support for Nested Objects in Typesense
Martin expressed the need for support for nested objects in Typesense. Kishore Nallan mentioned the possibility of flattening objects before indexing and restoring them later. An issue has been created on GitHub to track this.

Using Typesense to Query by Custom Column Key Value
Sandip asked how to use Typesense to perform unique key searches in different organizations. Kishore Nallan suggested creating an 'object' field for varying keys. After a clarification, Sandip expressed satisfaction with the advice.