#community-help

Creating Schema for Nested Objects in JSON

TLDR Greg asked about creating schemas for nested objects in JSON. Jason provided information about indexing nested fields in Typesense v0.24.0. PneuViz requested details about replacing the 'highlights' field with 'highlight' in the new version.

Powered by Struct AI

1

Sep 23, 2022 (13 months ago)
Greg
Photo of md5-11c0f771a29e2aa8d72ae9544cc39017
Greg
08:31 PM
Question: How would I create the schema for nested objects? This is my JSON:
{
    "contributors": {
        "contributor1": {
            "bio": "Some bio",
            "firstName": "John",
            "lastName": "Doe",
            "type": "author"
        },
        "contributor2": {
            "bio": "Another bio",
            "firstName": "Jane",
            "lastName": "Joe",
            "type": "editor"
        },
        "contributor3": {
            "bio": "An even better bio",
            "firstName": "Billy",
            "lastName": "Jean",
            "type": "influencer"
        }
    }
}
08:31
Greg
08:31 PM
There can be many contributors so it is not a fixed list.
08:33
Greg
08:33 PM
I could also do it as an array
{
    "contributors": [{
            "bio": "Some bio",
            "firstName": "John",
            "lastName": "Doe",
            "type": "author"
        },
        {
            "bio": "Another bio",
            "firstName": "Jane",
            "lastName": "Joe",
            "type": "editor"
        },
        {
            "bio": "An even better bio",
            "firstName": "Billy",
            "lastName": "Jean",
            "type": "influencer"
        }
    ]

}
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
08:35 PM
Side note: Nested objects are only supported in the latest RC build of v0.24.0.

If you’re running 0.24.0, here’s how to index nested fields: https://github.com/typesense/typesense/issues/227#issuecomment-1211666924
Greg
Photo of md5-11c0f771a29e2aa8d72ae9544cc39017
Greg
08:38 PM
Jason, I am using Typesense Cloud. I assume that version is not available?
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
08:43 PM
We can upgrade you from our side to that RC build. Could you DM me your cluster ID?

1

Oct 10, 2022 (12 months ago)
PneuViz
Photo of md5-d3a91f1c73070bc0831630e3c4aa3d02
PneuViz
06:30 PM
Jason I noticed that the new version doesn't use highlights anymore. The new highlight feature doesn't show the highlight in the snippets like they did in 0.24.0rc4. I'm working with typescript so I would like to get a little more details on how to support this change.
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
08:21 PM
PneuViz In the new version, we’ve introduced a new field called highlight which will include highlights for all fields, including nested fields. There should still be a field called highlights (plural) which lists all highlights for non-nested fields.