Hi all, I have a question about nested objects! I...
# community-help
i
Hi all, I have a question about nested objects! I'd like to have a schema like this:
Copy code
{
    storeName: "Best Slice Shop"
    products: [{
       id: 123,
       name: pizza,
       ingredients: ["Tomatoes", "Garlic", ... ]
    }
]
But it looks like I can only define types on one layer deep (ref https://github.com/typesense/typesense/issues/227#issuecomment-1364072388), e.g.
Copy code
{
    "enable_nested_fields": true,
    "name": "store",
    "fields": [
        {
			"name": "products",
			"type": "object[]"
		},
		{
			"name": "products.id",
			"type": "int[]"
		},
		{
			"name": "products.name",
			"type": "string[]"
		},
		{
			"name": "products.ingredients",
			"type": "string[][]" <-- doesn't work
		}
    ]
}
Is there a way to define a field to be list of strings on an list of objects field? Thank you!!
j
Interesting! Could you try this and see what happens:
Copy code
{
  "name": "products.ingredients",
  "type": "string[]"
}
Hang on
Let’s try something else
Could you use this schema:
Copy code
{
    "enable_nested_fields": true,
    "name": "store",
    "fields": [
        {
			"name": "products",
			"type": "object[]"
	},
    ]
}
then index one of your documents and then look at the updated collection schema which Typesense generates and check the field type for
products.ingredients
?
πŸ™Œ 1
i
Ok it looks like it's string[]! Interesting. Thank you!
Copy code
{
      "facet": false,
      "index": true,
      "infix": false,
      "locale": "",
      "name": "products.ingredients",
      "optional": true,
      "sort": false,
      "type": "string[]"
    },
Copy code
[ { "id": "123", "ingredients": [ "Tomatoes", "Garlic" ], "name": "pizza" } ]
πŸ‘ 1
j
Btw, on a side note, the most generic field definition takes precedence in the collection schema. So if you have both
products
and
products.ingredients
explicitly listed, then products will take precedence and index all nested fields
πŸ™ 1
i
Ah ok that makes sense and clarifies things, thank you!
πŸ‘ 1