Hi team, could I get some suggestions on how to op...
# community-help
m
Hi team, could I get some suggestions on how to optimize my Typesense query? Currently this query runs 2.3s which is super slow, I found the bottleneck comes from
filterBy
, and filterBy looks like:
metric1:=[TYPE_A,TYPE_B,TYPE_C,TYPE_D] && metric2:!=[VALUE_1,VALUE_2,VALUE_3] && metric3:>0 && metric4:<0.99 && (metric5:>10000 || metric1:=TYPE_D) && (metric6:>100000 && (metric1:=TYPE_D || metric6:>1000)) && (metric1:!='TYPE_A' || metric7:true || metric8:true)
, basically we have many filters and each filter contributes 300ms - 600ms and overall it's 2.3s.
j
You want to try switching
:=
to
:
if those fields only have values with a single word without spaces. You also want to set
range_index: true
in the schema definition for any fields that you use with the > or < operators
m
thx for responding! I tried switching := to ; but it doesn't help since there is only one filter using that, also I didn't see range_index in typescript type, is 'sort' the same thing?
ok I added range_index and will try
j
range_index is different for sort. The typescript type is missing for range index, if you still add it with a ts-ignore, the API will accept it
❤️ 1
CC: @Fanis Tharropoulos could you add the missing type?
f
Added it, though this shouldn't pose a typescript error, just no autocomplete:
Copy code
export interface CollectionFieldSchema {
  name: string;
  type: FieldType;
  optional?: boolean;
  facet?: boolean;
  index?: boolean;
  sort?: boolean;
  locale?: string;
  infix?: boolean;
  stem?: boolean;
  num_dim?: number;
  store?: boolean;
  range_index?: boolean; // even if missing the next one will take care of it
  [t: string]: unknown; // this just says that it's a Record<string, unknown>, so anything with a key of string goes
}
m
Guys thank you for your help! I've set up a sample with 600 documents and found adding
range_index
indeed brings down the query time by 80%! I'll try to do this for our prod schema.
🙌 2