#community-help

Resolving Algolia Filter Issue with Empty/Null Strings

TLDR Mateo was struggling with a filtering error when dealing with empty/null strings in Algolia. Upon Jason's suggestion, they changed empty values to "Unknown" and exported the documents to resolve the issue.

Powered by Struct AI
+11
9
7mo
Solved
Join the chat
Jan 30, 2023 (8 months ago)
Mateo
Photo of md5-f930fdb99fd46477205fa1201164ea50
Mateo
02:11 PM
Hey guys! good morning!
I'm receiving an empty option in some of the filters from Algolia, I think is actually expected as some records could have this field as empty/null, I wonder how could we filter_by this field as an empty/null string? this is the request we're sending but we get no results even though there are 3 records that match.

<https://0b3w9ohegr1sljm6p-1.a1.typesense.net/collections/appointment_development/documents/search?query_by=confirmation_id,purchase_order_identifiers&amp;num_typos=0&amp;exhaustive_search=true&amp;highlight_full_fields=confirmation_id,purchase_order_identifiers&amp;q=*&amp;facet_by=arrival_time,facility_name,checkin_status,scheduler_name,equipment_type_id,status,appointment_type_name,created_by_name&amp;filter_by=equipment_type_id:=''&amp;max_facet_values=10&amp;page=1&amp;per_page=25>
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
08:24 PM
Mateo Typesense is unable to match on empty values, even though it facets on them. I would recommend setting empty strings to something like “Unknown” or “N/A” so it’s string, then be able to filter on it
Mateo
Photo of md5-f930fdb99fd46477205fa1201164ea50
Mateo
10:39 PM
Got it, is there a way to check if these 3 elements it says exists with an empty value in this field actually exists and are present in this collection in Typesense? We're using the Typesense server and Typensense cloud
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
10:41 PM
Not by querying Typesense directly… I’d recommend querying your primary datastore
Mateo
Photo of md5-f930fdb99fd46477205fa1201164ea50
Mateo
10:48 PM
I tried this but did not find any record with that field as null in our dev DB, maybe I need to reindex and see if they're gone
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
10:51 PM
Another way could be to export the documents from the collection using the export endpoint, and then search through the JSONL file
Jan 31, 2023 (8 months ago)
Mateo
Photo of md5-f930fdb99fd46477205fa1201164ea50
Mateo
12:37 AM
That's a good idea, which is the export endpoint?
Feb 01, 2023 (7 months ago)
Mateo
Photo of md5-f930fdb99fd46477205fa1201164ea50
Mateo
02:51 PM
Thanks Jason with this approach we were able to resolve the problem!
+11