#community-help

Managing Nested Objects and Indexing in Collections

TLDR Maxi had trouble managing nested objects and their indexing. Jason suggested using separate collections and provided an example on how to structure the data for filtering.

Powered by Struct AI

1

9
9mo
Solved
Join the chat
Feb 24, 2023 (9 months ago)
Maxi
Photo of md5-d3c1ea3951b2e0286085d33d1eb9fdf7
Maxi
06:57 PM
Hey everyone! I'm having some trouble managing nested objects and their indexing.

Currently I have the following object on the collection:
{
  ...
  personCalendars: [{
    id: '1',
    calendar: [{
      startDate: 1664064000,
      endDate: 1664068000
    }, {
      startDate: 1664074000,
      endDate: 1664078000
    }]
  }, {
    id: '2',
    calendar: [{
      startDate: 1664064000,
      endDate: 1664068000
    }, {
      startDate: 1664074000,
      endDate: 1664078000
    }]
  }],
  ...
}

I would need to make a search that returns a document only if the calendar of a person inside the personCalendars nested object is not between two dates that i pass on a query (startDate and endDate ).

Is that possible with the mentioned schema? Because I think it would flatten the personCalendars calendars into a personCalendars.calendar.startDate array and a personCalendars.calendar.endDate array, mixing both data
07:57
Jason
07:57 PM
So you would have to create a collection called say availabilities, and have a structure like:
{ calendar_id: 1, startDate: 1664064000, endDate: 1664068000 }
{ calendar_id: 1, startDate: 1664074000, endDate: 1664078000 }
{ calendar_id: 2, startDate: 1664064000, endDate: 1664068000 }
{ calendar_id: 2, startDate: 1664074000, endDate: 1664078000 }
Maxi
Photo of md5-d3c1ea3951b2e0286085d33d1eb9fdf7
Maxi
08:32 PM
Hmmm okay, we'll see how to approach this. Thanks!
08:33
Maxi
08:33 PM
Our only problem would be that we would want to still have some filters on the first persons collection, and add the calendar filters on top of that. Isn't having two collections for one filter an issue?
Feb 26, 2023 (9 months ago)
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
12:44 AM
You could put all person details inside the bookings collection
Feb 27, 2023 (9 months ago)
Maxi
Photo of md5-d3c1ea3951b2e0286085d33d1eb9fdf7
Maxi
12:38 PM
Hmmm okay, but if I want to retrieve only person details from the bookings collection, I should make a facet from the person ID (for example) and then group by that person ID after applying the filters, right?
12:38
Maxi
12:38 PM
Thanks for the help!

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

User-Specific Tagging and Filtering in UI

bnfd asked for the best way to create user-specific tags available on the UI. Jason suggested using personalized filters and creating a separate collection for each user's movies. The duo clarified the use of 'tags' in schemas and the refinementList widget in instantsearch. They also discussed various approaches to import and search large document collections.

1

46
29mo
Solved

Handling Field Variations in Typesense for Different Clients

Yoshi asked for a solution to handle varying contact_date fields for different clients in typesense. Jason recommended using nested fields for the short-term and mentioned future support for joining data across collections.

1

18
7mo
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

Resolving Auto-Schema and Configuration Issues in Typesense

Narayan was struggling with auto-schema and configuration issues in Typesense. With the help of Kishore Nallan, they understood and solved the problems by adding 'optional' to all nested fields. They will find a way to handle 'None'.

1

17
2mo
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