```"fields": [ // Other fields... // Incl...
# community-help
a
Copy code
"fields": [
    // Other fields...

    // Include indexing for fields within the variants object
    {"name": "variants", "type": "object[]", "facet": true, "index": true},
    {"name": "variants.combination", "type": "string[]", "facet": true},
    {"name": "variants.ssin", "type": "string", "facet": true},
    {"name": "variants.brandSku", "type": "string", "facet": true},
    {"name": "variants.sellingPrice", "type": "int32", "facet": true},
    {"name": "variants.finalListingPrice", "type": "int32", "facet": true},
    {"name": "variants.internalDiscountPercentage", "type": "int32", "facet": true},
k
This will work.
a
but it returns in search response as flat key value pairs not as an object
Copy code
"hits": [
    {
      "document": {
        "brand.cover": "String Value",
        "brand.description": "String Value",
        "brand.id": "String Value",
        "brand.logo": "String Value",
        "brand.name": "String Value",
k
Can you please tell me the version of Typesense you are using?
@Amrit Sharma Can you also please give me a sample document I can try locally with?
I see that you have already given a sample document earlier. Please tell me the version of TS you are using. I will look into what's happening.
a
“typesense”: “^1.5.3",
k
I mean the server version
That's the client version I think
a
ok wait
Typesense v0.24.1
k
Ok can you try this. Create new collection with only those variants related fields. Then index a sample document. And then try fetching it back. Let me know if the same issue occurs?
a
ok
k
@Amrit Sharma Alternatively can you please post the full schema you are using and a sample document? I can also try on my end.
j
@Amrit Sharma Are you using the Firestore Typesense extension by any chance?
a
no
Copy code
const fields: Array<CollectionFieldSchema> = [
      { name: 'productId', type: 'string' },
      { name: 'name', type: 'string' },
      { name: 'hsn', type: 'string', index: false, optional: true },
      { name: 'gstRate', type: 'int32', index: false, optional: true },
      { name: 'originCountry', type: 'string' },
      { name: 'shortDescription', type: 'string' },
      { name: 'longDescription', type: 'string' },
      { name: 'prescriptionRequired', type: 'bool' },
      { name: 'isReturnable', type: 'bool' },
      { name: 'cancelation.isCancelable', type: 'bool' },
      {
        name: 'cancelation.cancelationWindow',
        type: 'int32',
        index: false,
        optional: true,
      },
      { name: 'manufacturer.name', type: 'string', facet: true },
      { name: 'manufacturer.address', type: 'string', facet: true },
      { name: 'manufacturer.contact', type: 'string', facet: true },
      { name: 'warranty.isApplicable', type: 'bool', facet: true },
      { name: 'brand.id', type: 'string', facet: true },
      { name: 'brand.name', type: 'string', facet: true },
      { name: 'brand.description', type: 'string', facet: true },
      { name: 'brand.logo', type: 'string', index: false, optional: true },
      { name: 'brand.cover', type: 'string', index: false, optional: true },
      { name: 'category.id', type: 'string', facet: true },
      { name: 'category.name', type: 'string', facet: true },
      { name: 'subcategory.id', type: 'string', facet: true },
      { name: 'subcategory.name', type: 'string', facet: true },
      { name: 'tag.id', type: 'string' },
      { name: 'tag.name', type: 'string' },
      { name: 'variants.combination', type: 'string[]' },
      { name: 'variants.ssin', type: 'string', index: false, optional: true },
      { name: 'variants.brandSku', type: 'string', facet: true },
      { name: 'variants.sellingPrice', type: 'int32' },
      { name: 'variants.finalListingPrice', type: 'int32' },
      {
        name: 'variants.internalDiscountPercentage',
        type: 'int32',
        facet: true,
      },
    ];
    const productSchema = {
      name: 'products',
      fields,
      default_sorting_field: 'variants.finalListingPrice',
      enable_nested_fields: true,
    };

    return await client.collections().create(productSchema);
Copy code
Response 

{
  "created_at": 1683730309,
  "default_sorting_field": "variants.finalListingPrice",
  "enable_nested_fields": true,
  "fields": [
    {
      "facet": false,
      "index": true,
      "infix": false,
      "locale": "",
      "name": "productId",
      "optional": false,
      "sort": false,
      "type": "string"
    },
    {
      "facet": false,
      "index": true,
      "infix": false,
      "locale": "",
      "name": "name",
      "optional": false,
      "sort": false,
      "type": "string"
    },
    {
      "facet": false,
      "index": false,
      "infix": false,
      "locale": "",
      "name": "hsn",
      "optional": true,
      "sort": false,
      "type": "string"
    },
    {
      "facet": false,
      "index": false,
      "infix": false,
      "locale": "",
      "name": "gstRate",
      "optional": true,
      "sort": true,
      "type": "int32"
    },
    {
      "facet": false,
      "index": true,
      "infix": false,
      "locale": "",
      "name": "originCountry",
      "optional": false,
      "sort": false,
      "type": "string"
    },
    {
      "facet": false,
      "index": true,
      "infix": false,
      "locale": "",
      "name": "shortDescription",
      "optional": false,
      "sort": false,
      "type": "string"
    },
    {
      "facet": false,
      "index": true,
      "infix": false,
      "locale": "",
      "name": "longDescription",
      "optional": false,
      "sort": false,
      "type": "string"
    },
    {
      "facet": false,
      "index": true,
      "infix": false,
      "locale": "",
      "name": "prescriptionRequired",
      "optional": false,
      "sort": true,
      "type": "bool"
    },
    {
      "facet": false,
      "index": true,
      "infix": false,
      "locale": "",
      "name": "isReturnable",
      "optional": false,
      "sort": true,
      "type": "bool"
    },
    {
      "facet": false,
      "index": true,
      "infix": false,
      "locale": "",
      "name": "cancelation.isCancelable",
      "optional": false,
      "sort": true,
      "type": "bool"
    },
    {
      "facet": false,
      "index": false,
      "infix": false,
      "locale": "",
      "name": "cancelation.cancelationWindow",
      "optional": true,
      "sort": true,
      "type": "int32"
    },
    {
      "facet": true,
      "index": true,
      "infix": false,
      "locale": "",
      "name": "manufacturer.name",
      "optional": false,
      "sort": false,
      "type": "string"
    },
    {
      "facet": true,
      "index": true,
      "infix": false,
      "locale": "",
      "name": "manufacturer.address",
      "optional": false,
      "sort": false,
      "type": "string"
    },
    {
      "facet": true,
      "index": true,
      "infix": false,
      "locale": "",
      "name": "manufacturer.contact",
      "optional": false,
      "sort": false,
      "type": "string"
    },
    {
      "facet": true,
      "index": true,
      "infix": false,
      "locale": "",
      "name": "warranty.isApplicable",
      "optional": false,
      "sort": true,
      "type": "bool"
    },
    {
      "facet": true,
      "index": true,
      "infix": false,
      "locale": "",
      "name": "brand.id",
      "optional": false,
      "sort": false,
      "type": "string"
    },
    {
      "facet": true,
      "index": true,
      "infix": false,
      "locale": "",
      "name": "brand.name",
      "optional": false,
      "sort": false,
      "type": "string"
    },
    {
      "facet": true,
      "index": true,
      "infix": false,
      "locale": "",
      "name": "brand.description",
      "optional": false,
      "sort": false,
      "type": "string"
    },
    {
      "facet": false,
      "index": false,
      "infix": false,
      "locale": "",
      "name": "brand.logo",
      "optional": true,
      "sort": false,
      "type": "string"
    },
    {
      "facet": false,
      "index": false,
      "infix": false,
      "locale": "",
      "name": "brand.cover",
      "optional": true,
      "sort": false,
      "type": "string"
    },
    {
      "facet": true,
      "index": true,
      "infix": false,
      "locale": "",
      "name": "category.id",
      "optional": false,
      "sort": false,
      "type": "string"
    },
    {
      "facet": true,
      "index": true,
      "infix": false,
      "locale": "",
      "name": "category.name",
      "optional": false,
      "sort": false,
      "type": "string"
    },
    {
      "facet": true,
      "index": true,
      "infix": false,
      "locale": "",
      "name": "subcategory.id",
      "optional": false,
      "sort": false,
      "type": "string"
    },
    {
      "facet": true,
      "index": true,
      "infix": false,
      "locale": "",
      "name": "subcategory.name",
      "optional": false,
      "sort": false,
      "type": "string"
    },
    {
      "facet": false,
      "index": true,
      "infix": false,
      "locale": "",
      "name": "tag.id",
      "optional": false,
      "sort": false,
      "type": "string"
    },
    {
      "facet": false,
      "index": true,
      "infix": false,
      "locale": "",
      "name": "tag.name",
      "optional": false,
      "sort": false,
      "type": "string"
    },
    {
      "facet": false,
      "index": true,
      "infix": false,
      "locale": "",
      "name": "variants.combination",
      "optional": false,
      "sort": false,
      "type": "string[]"
    },
    {
      "facet": false,
      "index": false,
      "infix": false,
      "locale": "",
      "name": "variants.ssin",
      "optional": true,
      "sort": false,
      "type": "string"
    },
    {
      "facet": true,
      "index": true,
      "infix": false,
      "locale": "",
      "name": "variants.brandSku",
      "optional": false,
      "sort": false,
      "type": "string"
    },
    {
      "facet": false,
      "index": true,
      "infix": false,
      "locale": "",
      "name": "variants.sellingPrice",
      "optional": false,
      "sort": true,
      "type": "int32"
    },
    {
      "facet": false,
      "index": true,
      "infix": false,
      "locale": "",
      "name": "variants.finalListingPrice",
      "optional": false,
      "sort": true,
      "type": "int32"
    },
    {
      "facet": true,
      "index": true,
      "infix": false,
      "locale": "",
      "name": "variants.internalDiscountPercentage",
      "optional": false,
      "sort": true,
      "type": "int32"
    }
  ],
  "name": "products",
  "num_documents": 0,
  "symbols_to_index": [],
  "token_separators": []
}
k
@Amrit Sharma Please post a sample document as well.
a
@Kishore Nallan yes
k
I am actually getting a schema error when I try to index with that document and schema.
variants.sellingPrice
must be an array since it's inside an array of objects.
How did you manage to index your data past this?
@Amrit Sharma
a
Previously i was trying this
Copy code
<https://typesense-community.slack.com/archives/C01P749MET0/p1683717787892319>
for variants
but u told me this will work
Copy code
"fields": [
    // Other fields...

    // Include indexing for fields within the variants object
    {"name": "variants", "type": "object[]", "facet": true, "index": true},
    {"name": "variants.combination", "type": "string[]", "facet": true},
    {"name": "variants.ssin", "type": "string", "facet": true},
    {"name": "variants.brandSku", "type": "string", "facet": true},
    {"name": "variants.sellingPrice", "type": "int32", "facet": true},
    {"name": "variants.finalListingPrice", "type": "int32", "facet": true},
    {"name": "variants.internalDiscountPercentage", "type": "int32", "facet": true},
k
My bad, I got a bit mixed up with those 2 messages.
Can you please try that with the array type and see what happens?
a
Copy code
{
        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', facet: true },
          { name: 'finalListingPrice', type: 'int32', facet: true },
          { name: 'internalDiscountPercentage', type: 'int32', facet: true },
        ],
      },
Copy code
const productSchema = {
      name: 'products',
      fields,
      default_sorting_field: 'finalListingPrice',
      enable_nested_fields: true,
    };
Request failed with HTTP code 400 | Server said: Default sorting field is defined as
finalListingPrice
but is not found in the schema.
also tried variants.finalListingPrice
got same error
k
Integer field in array of object cannot be sorted upon because it's stored as integer array and we can't sort on that because we won't know which value to pick.
So those fields must be
sort: false
or just omit the sort property.
a
i want to add more fields in query_by
from docs
k
Should be a string of comma separated fields. e.g.
"productId,name"
-- not an array.
Check the JS code snippets in the docs for reference.