Indexing Nested Fields in Arrays
TLDR 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[].
May 17, 2023 (4 months ago)
Amrit
09:09 AMconst fields: Array<CollectionFieldSchema> = [
{ name: 'productId', type: 'string' },
{ name: 'name', type: 'string' },
{
name: 'brand',
type: 'object',
facet: true,
index: true,
fields: [
{ name: 'name', type: 'string', facet: true },
{ name: 'description', type: 'string', index: false, optional: true },
{ name: 'logo', type: 'string', index: false, optional: true },
{ name: 'cover', type: 'string', index: false, optional: true },
],
},
{
name: 'variants',
type: 'object[]',
facet: true,
index: true,
fields: [
{ name: 'combination', type: 'string[]', facet: true },
{ name: 'ssin', type: 'string' },
{ name: 'brandSku', type: 'string', facet: true },
{ name: 'sellingPrice', type: 'int32' },
{ name: 'finalListingPrice', type: 'int32' },
{ name: 'internalDiscountPercentage', type: 'int32' },
],
},
];
this is not indexing nested fields
Kishore Nallan
09:14 AMtype: object[]
for variants field and then inside it again have a list of fields.Kishore Nallan
09:15 AM{
name: 'variants',
type: 'object[]',
facet: true,
index: true,
fields: [
{ name: 'combination', type: 'string[]', facet: true },
{ name: 'ssin', type: 'string' },
{ name: 'brandSku', type: 'string', facet: true },
{ name: 'sellingPrice', type: 'int32' },
{ name: 'finalListingPrice', type: 'int32' },
{ name: 'internalDiscountPercentage', type: 'int32' },
],
},
Kishore Nallan
09:17 AM{"name": "variants.combination", "type": ...}
Kishore Nallan
09:17 AMAmrit
10:03 AMAmrit
10:03 AMAmrit
10:04 AMvariants: [
{
combination: ['2 MONTH'],
ssin: 'SOSHS1311',
brandSku: 'PG-120-2 MONTHS',
sellingPrice: 2300,
finalListingPrice: 2300,
internalDiscountPercentage: 0,
},
{
combination: ['1 MONTH'],
ssin: 'SOSHS1310',
brandSku: 'PG-60-1 MONTHS',
sellingPrice: 1200,
finalListingPrice: 1200,
internalDiscountPercentage: 0,
},
data that i try to insert
Kishore Nallan
10:14 AMKishore Nallan
10:14 AMKishore Nallan
10:14 AMTypesense
Indexed 2764 threads (79% resolved)
Similar Threads
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.
Defining Nested Fields in Typesense Schema
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.



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.



Resolving Issue with Empty Arrays in the Filter
Rushil faced an issue with a filter not dismissing empty arrays. Kishore Nallan assisted them. The resolution was to input [] not [""] for an empty array.
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.