#community-help

Discussing Implementation of Nested Fields Feature

TLDR Stefan asks about modeling ingredients data in a database, but realizes it might reference too much for the search engine. Kishore Nallan confirms his query is IN search-related and mentions plans to support nested fields in later updates.

Powered by Struct AI

1

Feb 12, 2022 (23 months ago)
Stefan
Photo of md5-d6c265b4792dbf0a1d6ae378f39d8736
Stefan
12:25 PM
Hi!
Am I correct that there is currently no way to cover a use case like this:
Assuming I have a database of meals where each meal has X ingredients.
Each ingredient is present in a certain amount

In a perfect world I would model it like this:
ingredients: [
{
    name: "chicken",
    concentration: num
}
]


And then filter for it like this:
ingredients.name = 'chicken' AND ingredients.concentration >= 5

Where ingredients should refer to the same nested Object

While writing this I realized that this is probably way too much for typesense or any search engine to cover. This is something for a database. Asking it anyway just in case I am missing something.

Only idea I have to cover this use case is to go crazy and flatten the ingredients array like this:
chicken.present: bool
chicken.concentration: num

But given that there can be thousands of ingredients this would probably not scale well.
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
12:32 PM
I've seen that post before. This is a form of IN search where the filter comparison is applied within an object fields than across globally. When we add support for nested fields, we will have to support this as well. Mongo has operators for distinguishing between in-record and cross-record searches that we might take inspiration from.

The other way to solve this is with a join, which we are also exploring. In that case you will have a separate ingredients collection that has a reference id to the main recipe collection such that it will be trivial to filter on the ingredients and then join on the other fields from the recipe collection.
12:33
Kishore Nallan
12:33 PM
Supporting joins will probably cover a lot of cases where nested fields are useful.
Stefan
Photo of md5-d6c265b4792dbf0a1d6ae378f39d8736
Stefan
12:33 PM
Wow that would be awesome. Didn't expect this to be in the scope of the nested feature
12:35
Stefan
12:35 PM
really looking forward to this. If there is an alpha version I can test it in production 😅
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
12:38 PM
Joins or nested fields? 🙂 Both are only at conceptual spike stage at the moment.
Stefan
Photo of md5-d6c265b4792dbf0a1d6ae378f39d8736
Stefan
12:41 PM
I think for my particular use case the nested fields are a better fit. Using joins I would need to implement some kind of many to many relationship. Nested fields seems easier

1

Typesense

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

Indexed 3011 threads (79% resolved)

Join Our Community

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.

14
24mo
Solved

Discussions on Typesense, Collections, and Dynamic Fields

Tugay shares plans to use Typesense for their SaaS platform and asks about collection sizes and sharding. Jason clarifies Typesense's capabilities and shares a beta feature. They discuss using unique collections per customer and new improvements. Kishore Nallan and Gabe comment on threading and data protection respectively.

3

45
35mo
Solved

Issues Sorting Multiple Fields with Sort_by in Typesense Query

Rishabh was having trouble sorting two fields separately with a single query. Jason explained that a secondary sorting will only occur if the first sort results in matching values. They clarified the functionality of sorting in various search engines.

3

34
34mo

Issue with Sorting Search Request

Anton encounters an issue with sorting a search request due to an assuredly existing field appearing absent. Jason complements by revealing string sorting isn't supported. Kishore Nallan confirms future support for string sorting, despite its memory-demands.

1

13
31mo
Solved

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