#community-help

Handling Nested Objects in Typesense

TLDR 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.

Powered by Struct AI
Dec 27, 2021 (25 months ago)
Darren
Photo of md5-fa83de4db3e1444aecaf7a587e35eb16
Darren
10:09 AM
On of my data models has an array of objects. notifications[{ message: <string>, level: <string> } ... ] - seems like from the docs, I can't store this at typsense as there is no support for a nested object like this that I can turn into an array? I would have liked from the search results to show the level of any notifications in search results, but I guess I can't? Perhaps if I restructure it on indexing to be { '0': { message, level }, '1': { message, level } ... } ... thoughts?
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
10:19 AM
Typesense does not support indexing of array of objects. You can have those fields flattened out as array of strings. E.g.

messages: ["m1", "m2"]
levels: [1, 2, 3]

Then with some client side code you can show the level.
10:20
Kishore Nallan
10:20 AM
The other option is to index those messages as top level objects with message, level and notification_id fields, and then doing a group_by on notifications.
Darren
Photo of md5-fa83de4db3e1444aecaf7a587e35eb16
Darren
10:32 AM
Ok, I'll have to get creative with how I index these.
PS - just to confirm - typesense does support nested paths yes? eg <http://status.is:1|status.is:1> as a filter? Just asking because I can't results returned with such a filter and I couldn't find any reference or example in the docs that nested paths are supported
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
10:33 AM
We don't support any form of nesting. You can have a field with dots in the name, but they are not considered any different from any other character.
Darren
Photo of md5-fa83de4db3e1444aecaf7a587e35eb16
Darren
10:34 AM
Ah. Ok, I'll have to flatten the data at indexing also. Thanks
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
10:34 AM
So you can have a field name called <http://status.is|status.is> but it is just a regular field name. People use dots to refer to fields that they "flatten" out this way prior to indexing.
Darren
Photo of md5-fa83de4db3e1444aecaf7a587e35eb16
Darren
10:36 AM
Yeah, got it, thanks. Past experience with Algolia, I recall having nested structures so I assumed I could here. No worries. Thanks.
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
10:36 AM
Yeah, it's on our roadmap to support next year 🙂
Darren
Photo of md5-fa83de4db3e1444aecaf7a587e35eb16
Darren
10:46 AM
You guys are on 🔥! Great product. You deserve every success!
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
10:46 AM
Thank you!
12:54
Kishore Nallan
12:54 PM
Darren just to be sure. If you don't intend to search on nested documents they can certainly be part of the document. They will be stored and returned in the response verbatim. What we don't support is the ability to index and search on nested fields.
Darren
Photo of md5-fa83de4db3e1444aecaf7a587e35eb16
Darren
02:14 PM
Yeah, I understand. I did need to facet them. But its ok, I haven't locked in my serializer/unserializer to/from typesense db, so I will flatten them. Better for your product of course if you didn't need to ... next year ...
Jan 04, 2022 (24 months ago)
Martin
Photo of md5-4c44d17869045701f2ca4035972ad4c5
Martin
05:02 AM
We discussed this before and I look forward to Typesense supporting searching in objects/nested structures. I have a standard use case with a blog with posts and authors, and for now solve it my flattening the authors field (into authors and author_ids).

Typesense

Lightning-fast, open source search engine for everyone | Knowledge Base powered by Struct.AI

Indexed 3015 threads (79% resolved)

Join Our Community

Similar Threads

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.

1

18
28mo

Configuring Typesense Extension for Nested Fields in Firebase Collection

David had issues indexing nested fields using the Typesense extension. Jason offered advice on specifying schemas and prioritizing specific fields, but there remained unresolved challenges with the schema.

4

14
7mo

Discussing Issues and Improvements for Typesense

Greg shared feedback and raised questions about Typesense, specifically about nested objects, rate limiting, and documentation. Kishore Nallan provided explanations, confirming that non-searchable fields can be stored and noting to improve documentation clarity.

2

4
32mo

Nested Objects Issue in Firebase & Typesense Integration

Shaun encountered issues with nested objects being flattened in Typesense. Jason found the root issue and provided a solution involving updating the Firebase extension to 1.0.3.

7

57
6mo

Querying with Typesense-Js and Handling Null Values

michtio was querying using typesense-js and receiving fewer results than expected. Kishore Nallan suggested using different query parameters. Further discussion led to the handling of 'null' values and filtering syntax in the search queries. The thread ended with Jason offering migration support from Algolia to Typesense.

4

39
17mo