Hi! Am I correct that there is currently no way to...
# community-help
s
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:
Copy code
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.
k
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.
Supporting joins will probably cover a lot of cases where nested fields are useful.
s
Wow that would be awesome. Didn't expect this to be in the scope of the nested feature
really looking forward to this. If there is an alpha version I can test it in production 😅
k
Joins or nested fields? 🙂 Both are only at conceptual spike stage at the moment.
s
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