#community-help

Solutions for Filtering and Comparing Data in Typesense

TLDR Jason needed to filter data in Typesense. Jason suggested using unix timestamps for comparison and creating a new field for empty records. Kishore Nallan confirmed the syntax for cross-field ORs.

Powered by Struct AI
Dec 09, 2022 (12 months ago)
Jason
Photo of md5-c7ebbbcac16a1763e16d0e8e8177b0ae
Jason
07:43 PM
I'm trying to filter where something is greater than or equal or empty. is this possible?

Case: I want to filter documents by date_start where date_start >= "2022-12-09" || date_start = ""
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
07:44 PM
You would have to store the date as a unix timestamp, then you can do numerical comparison.

For “is empty”, Typesense doesn’t have a way to filter these records directly. You would instead have to create a new field that’s computed by you at indexing time, for eg is_date_start_empty: true|false and then you can filter with that boolean field in your filter
07:45
Jason
07:45 PM
On a side note, being able to do ORs across fields is only supported in the latest RC build of 0.24
Dec 10, 2022 (12 months ago)
Jason
Photo of md5-c7ebbbcac16a1763e16d0e8e8177b0ae
Jason
07:45 AM
ah yes, I do have the timestamp as unix timestamp - forgot about that when writing my example case
07:46
Jason
07:46 AM
Our clusters are Typesense v0.24.0.rcn25
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
03:56 PM
That should have cross-field ORs
Jason
Photo of md5-c7ebbbcac16a1763e16d0e8e8177b0ae
Jason
05:05 PM
Is the syntax for that (field1 := condition || field2 := condition) ? and can it be cross field on the same field e.g. feild1 >= 123 || field1 := 0 ?
Dec 11, 2022 (12 months ago)
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
05:42 AM
Yes, and yes.