#community-help

Trouble with 'q' Parameter in Typesense query

TLDR ryosuke_shiomi was having trouble with a Typesense query involving the 'q' parameter. Kishore Nallan suggested a temporary workaround and proposed using the latest builds to fix the issue. The solution was under trial at the end of the thread.

Powered by Struct AI
Mar 11, 2022 (20 months ago)
ryosuke_shiomi
Photo of md5-f1a76953537941ddfcf52f715f48ebff
ryosuke_shiomi
07:14 AM
I think param ‘q’ does not work in well.
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
07:24 AM
Can you please post the schema of your collection? The query_by clause requires a list of fields, but I see that in your query you have -${userId1} -${userId2} -${userId3} … which is strange.
ryosuke_shiomi
Photo of md5-f1a76953537941ddfcf52f715f48ebff
ryosuke_shiomi
07:29 AM
Kishore Nallan sorry, field “query_by” and “q” are reverse in content,
In exactly,
const searchParams = {
  q: "-${userId1} -${userId2} -${userId3} …",
  query_by: "userId",
  filter_by: "favoriteGame: APEX"
}
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
07:34 AM
Okay can you tell me what the type of the userId field? Is it an array of user IDs or just a single user ID?
ryosuke_shiomi
Photo of md5-f1a76953537941ddfcf52f715f48ebff
ryosuke_shiomi
07:38 AM
userId type is string, and it is single.
schema is it (it is not all params because the app is not mine, is my office’s.)
collection 'users'

userId: string
favGame: string
createdAt: Date(int)
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
07:40 AM
The issue is that when you query this way, you actually see results with those excluded user IDs in the result is it?
ryosuke_shiomi
Photo of md5-f1a76953537941ddfcf52f715f48ebff
ryosuke_shiomi
07:42 AM
YES! but it does not work in this way.
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
07:43 AM
I will look into this. As a temporary workaround, can you try this:

q: "*",
filter_by: "favoriteGame: APEX && userId:!= [${userId1}, ${userId2}, ${userId3}]"
ryosuke_shiomi
Photo of md5-f1a76953537941ddfcf52f715f48ebff
ryosuke_shiomi
07:44 AM
ok, thank you for answering it!
After I try it, i would report the result.
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
07:59 AM
ryosuke_shiomi I think this issue is fixed on the latest 0.23 RC builds. Would you be able to try that? How are you using Typesense: Docker or Linux binary? I can make a recent RC build available to you for testing.
ryosuke_shiomi
Photo of md5-f1a76953537941ddfcf52f715f48ebff
ryosuke_shiomi
08:13 AM
Kishore Nallan ok, I examinate it.
I tried the answer, but returned error.
what is the ‘facet field’?
results: [
    {
      code: 400,
      error: 'To perform exclude filtering, filter field `userId` must be a facet field.'
    }
  ]
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
08:16 AM
Oh right, the userId field need to have facet: true enabled in the schema for negation. You don't need this if the latest RC builds work.
ryosuke_shiomi
Photo of md5-f1a76953537941ddfcf52f715f48ebff
ryosuke_shiomi
08:16 AM
oh, really?
so I will try to use it.
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
08:26 AM
I mean, if you want to do negation in filter_by then that field needs to have facet enabled. To do negation in q field, if you use the 0.23 RC builds, the bug you faced earlier won't be there.
ryosuke_shiomi
Photo of md5-f1a76953537941ddfcf52f715f48ebff
ryosuke_shiomi
08:30 AM
ok.
so, please give me the information about how to use 0.23.
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
08:41 AM
Are you using Typesense Cloud or self hosting?
ryosuke_shiomi
Photo of md5-f1a76953537941ddfcf52f715f48ebff
ryosuke_shiomi
11:59 AM
Kishore Nallan cloud!
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
12:14 PM
Ok let me know your cluster ID and we can upgrade. Are you already using it on production? If so you will have to test locally first.