Defining Nested Fields in Typesense Schema
TLDR Ivy wanted to define a list of strings in a list of objects, and Jason suggested omitting the explicit field type for "products.ingredients". The schema generated the desired field type.
2
1
1
May 09, 2023 (5 months ago)
Ivy
09:20 PMI'd like to have a schema like this:
{
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.
{
"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!!
Jason
09:22 PM{
"name": "products.ingredients",
"type": "string[]"
}
Jason
09:23 PMJason
09:23 PMJason
09:24 PM{
"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
Ivy
09:41 PM {
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "products.ingredients",
"optional": true,
"sort": false,
"type": "string[]"
},```
[ { "id": "123", "ingredients": [ "Tomatoes", "Garlic" ], "name": "pizza" } ]```1
Jason
09:42 PMproducts
and products.ingredients
explicitly listed, then products will take precedence and index all nested fields1
Ivy
09:46 PM1
Typesense
Indexed 2779 threads (79% resolved)
Similar Threads
Indexing Nested Fields in Arrays
Amrit was trying to index nested fields in arrays but didn't use a flat format. Kishore Nallan suggested using dot notation and updating the type to int32[].
Resolving Issues with Reference Field in v0.26.0.rc11
Shaun reported problems applying the reference field in `v0.26.0.rc11`. The issue made the tested field disappear from UI, and an attempt to fix it resulted in an error. Harpreet suggested re-indexing data and promised to consider improving the feature in future updates. Harpreet is currently working on a related feature - sorting by reference field.
Typesense Nested Fields and Sorting Issue
Amrit faced a problem with search response not returning nested objects. Kishore Nallan tried to spot the issue in the schema, but a proper resolution was not reached.
Troubleshooting Typesense Collection with Nested Objects
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.
Defining Nested JSON Schema for Querying
Greg struggled in defining a schema for querying a JSON object with nested fields. Jason offered solutions, with the final resolution involving the use of "object" as a field type for the contributors in the schema.