#community-help

Issue with Query Hangs Identifying Different Collection Field Names

TLDR Kanak experiences query hangs when collection field names differ. Ahmed had an issue adding documents to collections, which was self-resolved. Kishore Nallan resolved Kanak's issue with the updated build.

Powered by Struct AI
5
4mo
Solved
Join the chat
Jul 28, 2023 (4 months ago)
Kanak
Photo of md5-ffe3dcc3a11f48c707d4160814a80319
Kanak
08:05 PM
Found what looks like a strange bug. I'm trying out the 0.26rc build with support for joins. Following the example use case in https://gist.github.com/kishorenc/037314619c3104970ae703b25aff2f51, I created a couple of collections, one for products and one for users. Then a third collection called CustomerProductPrices which holds references to productid, user_id, and a price.

As I was moving around the parameters and running filters, some queries were hanging. I think maybe I've narrowed it down to this: queries are hanging when the collection being queried (eg: Products) is being referenced by a different name in the referencing collection. Eg: if I use the field schema
{ name: "product", type: "string", reference: "Products.product_id" }

, searching for Products is hanging if I use a $CustomerProductPrices filter_by clause (User searches work fine with the filter though). Same if I change user_id to user in the referencing schema - searches on User hang, while searches on Products work fine. If product_id in Products is referenced _as
product_id in CustomerProductPrices, and user_id in Users is referenced as user_id in CustomerProductPrices, queries all seem to be working.
08:08
Kanak
08:08 PM
Here is some code (uses chance to generate dummy data)

const array = (length, items) => Array(length).fill(0).map(items);

await client.collections().create({
  name: "Products",
  fields: [
    { name: "product_idx", type: "string" },
    { name: "product_name", type: "string" },
  ],
});
await client.collections().create({
  name: "Users",
  fields: [
    { name: "user_id", type: "string" },
    { name: "user_name", type: "string" },
  ],
});

await client.collections().create({
  name: "CustomerProductPrices",
  fields: [
    { name: "user_id", type: "string", reference: "Users.user_id" },
    { name: "product_id", type: "string", reference: "Products.product_idx" },
    { name: "product_price", type: "float" },
  ],
});
let products = array(200, () => ({
  product_idx: chance.guid(),
  product_name: chance.sentence({
    words: chance.integer({ min: 1, max: 10 }),
  }),
}));
let users = array(200, () => ({
  user_id: chance.guid(),
  user_name: chance.word(),
}));

let customers = array(200, () => ({
  user_id: users[chance.integer({ min: 0, max: users.length - 1 })].user_id,
  product_id:
    products[chance.integer({ min: 0, max: products.length - 1 })].product_idx,
  product_price: chance.floating({ fixed: 2, min: 1 }),
}));
await client
  .collections("Products")
  .documents()
  .import(products, { action: "create" });
await client
  .collections("Users")
  .documents()
  .import(users, { action: "create" });
await client
  .collections("CustomerProductPrices")
  .documents()
  .import(customers, { action: "create" });
let result = await client
  .collections("Products")
  .documents()
  .search({
    q: "*",
    filter_by: `$CustomerProductPrices(user_id:=${customers[0].user_id})`,
    include_fields: `$CustomerProductPrices(product_price)`,
  });

As is, this query is hanging. If I change "product_idx" to "product_id" (so that referencing field matches), or if I change the collection being searched to "Users", the query works fine.
Ahmed
Photo of md5-051f535431ff484f44f165e9a0b696a5
Ahmed
09:16 PM
I couldn't add documents to the collection with field referencing another collection. I received this message :
Error importing document: Field `category_id_sequence_id` has been declared in the schema, but is not found in the document

field name is category_id for both collections
09:55
Ahmed
09:55 PM
I found the issue, I was sending a field with the name id
Jul 31, 2023 (4 months ago)
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
10:34 AM
Kanak We've fixed this issue. How are you using Typesense? Happy to share the updated build with you. If you are on Cloud, please DM me your cluster ID.