Hi all &amp; <@U01PL2YSG8L> <@U01NZ4D0LDD> Need su...
# community-help
t
Hi all & @Kishore Nallan @Jason Bosco Need suggestion: Best Practices for Indexing Nested Fields in Typesense Schema I’m working with a dataset where the indexing requirements have evolved over time. Initially, I only needed to index a few fields, so I extracted and stored them as top-level fields to simplify searching. However, as the requirements have grown, I now need to index several nested fields. Here’s an example of my current data structure:
Copy code
{
  "customer": {
    "name": "Customer Name"
  },
  "destination": {
    "appointment": {
      "start": {
        "date": "2024-01-01",
        "time": "12:00",
        "timezone": "America/New_York"
      }
    },
    "arrivalDateTime": {
      "date": "2024-01-02",
      "time": "14:00",
      "timezone": "America/New_York"
    },
    "departureDateTime": {
      "date": "2024-01-01",
      "time": "15:00",
      "timezone": "America/New_York"
    },
    "warehouse": {
      "address": {
        "city": "Destination City",
        "stateCode": "ST"
      }
    }
  },
  "origin": {
    "appointment": {
      "start": {
        "date": "2024-01-01",
        "time": "08:00",
        "timezone": "America/New_York"
      }
    },
    "arrivalDateTime": {
      "date": "2024-01-01",
      "time": "10:00",
      "timezone": "America/New_York"
    },
    "departureDateTime": {
      "date": "2024-01-01",
      "time": "11:00",
      "timezone": "America/New_York"
    },
    "warehouse": {
      "address": {
        "city": "Origin City",
        "stateCode": "ST"
      }
    }
  },
  "drivers": [
    {
      "phoneNumber": "1234567890"
    }
  ],
  "dispatchers": [
    {
      "email": "<mailto:dispatcher@example.com|dispatcher@example.com>"
    }
  ]
}
Fields I now need to index include: •
destination.appointment.start.date
destination.arrivalDateTime.date
destination.departureDateTime.date
destination.warehouse.address.city
destination.warehouse.address.stateCode
origin.appointment.start.date
origin.arrivalDateTime.date
origin.departureDateTime.date
origin.warehouse.address.city
origin.warehouse.address.stateCode
customer.name
drivers.phoneNumber
dispatchers.email
My Questions: 1. Flattening vs. Nested Indexing: Should I extract all these fields to top-level keys for indexing, or is it better to keep them nested? ◦ Are there performance implications or best practices to consider? 2. Search Optimization: Would indexing these deeply nested fields directly impact search performance compared to flat fields? 3. Future Scalability: If more nested fields need to be indexed later, how should I design my schema to accommodate these changes efficiently? Any advice or suggestions for structuring my data and schema to handle these requirements effectively would be greatly appreciated. Thank you!
f
The performance impact of nested records is minimal. During indexing, there's a small overhead from flattening nested JSON fields into dot notation (e.g.,
destination.warehouse.address.city
). During searching, there's a minor overhead from deleting these flattened fields before returning results, but it shouldn't even be noticeable
t
Great, Thanks