Refining Typesense Query to Exclude Specific IDs
TLDR Andrew was manually ignoring chat IDs in their Typesense query, wondering if there was a better approach. Jason confirmed the approach was correct but suggested simplifying by generating the IDs in an array format.
Dec 12, 2022 (9 months ago)
Andrew
05:41 PMSo I have a list of strings, 'ignoreIds'. To make sure the resulting query does not have a chatId in this list, i do the following:
String ignore = '';
//for each chatId, add it to a string that follows the form 'typsenseId:chatId || '
for (String chatId in ignoreIds) {
//if chatId is not the last element in the list, add ' || '
if (chatId != ignoreIds.last) {
ignore += 'chatId:!=$chatId && ';
} else {
//if chatId is the last element in the list, do not add ' || '
ignore += 'chatId:!=$chatId';
}
}
then in the query i have
'filter_by': '(senderId:$userId || receiverId:$userId) && pending:false && ($ignore)',
So that way the id's are ignored. It feels like theres a better way to do this tho lol
Jason
05:45 PMYou can simplify the last
$ignore
part by generating it in this format: chatId:!=[id1,id2,id3]
Typesense
Indexed 2764 threads (79% resolved)
Similar Threads
Resolving Typesense Error in Netlify Deployment
Bryan encountered a Typesense error during a Netlify deployment. Jason and Damian determined the problem lay with array signatures and executed a fix. Bryan confirmed this resolved the issue.


Querying TypeSense: Exclude Certain IDs from Array Field
Andrew asked if it's possible to exclude specific ids from an array in TypeSense, like Firestore's not-in array. Jason confirmed it's possible and shared how to do it, in addition to a reference link.

Querying with Not-in in Typesense
Masahiro inquired about using not-in queries in Typesense. Kishore Nallan explained how to conduct such queries by using the "-" operator in the query string, and assisted Masahiro with issues stemming from a high number of exclusion tokens. The problem was eventually resolved by switching to the `multi_search` endpoint.


