#community-help

Troubleshooting Typesense Collection with Nested Objects

TLDR Oskar was encountering problems in creating collections in Typesense with nested objects. Jason advised to ensure that the nested fields are defined as an array. Oskar was able to resolve the issue by rectifying the schema.

Powered by Struct AI
8
2mo
Solved
Join the chat
Sep 08, 2023 (2 months ago)
Oskar
Photo of md5-83931254f933ee178245d2ef80552827
Oskar
02:01 PM
Hi everyone, started using Typesense a couple of weeks ago. Thanks for a great tool Jason & Kishore! 🙂 Seems promising.
However, I’m seeing some strange behaviour. I’m not able to create a collection with nested object and specify the children of an object that should be indexed.
This works
{
      "facet": false,
      "index": false,
      "name": "sources.*",
      "optional": true,
      "type": "object"
}

This doesn’t seem to work to have an index on child property of object.
strange behaviour. I'm not able to create a collection 
{
      "facet": false,
      "index": true,
      "name": "sources.content",
      "optional": true,
      "type": "string"
 }

Thoughts?
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
02:02 PM
You want to make sure you have “enable_nested_fields: true” in the schema
02:03
Jason
02:03 PM
If you already have that, could you share a full curl command that creates the collection and the error you see?
Oskar
Photo of md5-83931254f933ee178245d2ef80552827
Oskar
02:06 PM
Thanks for quick reply. I get
> Server said: Field sources.content has an incorrect type. Hint: field inside an array of objects must be an array type as well.
02:06
Oskar
02:06 PM
Don’t have curl atm ,just editing in cluster UI
02:07
Oskar
02:07 PM
Perhaps, I defined the sources as object instead of object[] .Let me try
02:12
Oskar
02:12 PM
That was it. This works.
{
      "facet": false,
      "index": false,
      "name": "sources",
      "optional": true,
      "type": "object[]"
},
{
      "facet": false,
      "index": true,
      "name": "sources.content",
      "optional": true,
      "type": "string[]"
}

Noticed how the type for sources.content needs to be in string[]
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
02:47 PM
Ah yes! If you have an array of objects, then subfields would also be an array