Effective Document Deletion Strategies in Typesense
TLDR Adrian asked about deleting potentially non-existent documents. Pantelis suggested using IDs for document deletion or queries within delete function. Adrian decided to use query-based deletions.
Powered by Struct AI
7
4mo
Solved
Aug 08, 2023 (4 months ago)
Adrian
Adrian
02:29 PMIf I want to delete a document that may or may not exist. Would you suggest explicitly checking for the
Could not find a document with id:
error and treating that as a non error case, or is there a better way to do so? Perhaps deleting by query would be a better approachPantelis
Pantelis
02:32 PMwhat i did is i assigned an id to each document so i can query it by id and delete it or check if it exists. Checking by error seems to be dangerous in the sense that maybe tomorrow the error can change to something else.
Adrian
Adrian
02:38 PMGood idea. When you say query for it do you mean a search query or the retrieve endpoint? I presumed the retrieve endpoint could have the same issue
Pantelis
Pantelis
02:43 PMtypesenseClient.collection('your-collection').documents.delete('your-document-id')
If it is not found then i am catching the error. The delete accepts idOrQuery. So if you have assigned an id before in each of your documents then typesense will find it and delete it. When i want to delete a set of documents i use a query inside delete, for instance:
delete('submitted:=true')
which is going to find all the submitted documents in your schema and delete themAdrian
Adrian
02:47 PMI see. Thanks for the input!
02:47
Adrian
02:47 PMI think I will go with the approach of deleting by query for all documents
Pantelis
Pantelis
02:48 PMyw, whatever suits your case better! 🙂
Typesense
Lightning-fast, open source search engine for everyone | Knowledge Base powered by Struct.AI
Indexed 3011 threads (79% resolved)
Similar Threads
Deleting Documents from Typesense Cloud and Version Upgrade
Masahiro asked how to remove documents from Typesense. Kishore Nallan clarified it varies by version and suggested upgrading from 0.20 to 0.22. Masahiro agreed to test this.
9
25mo
Solved
Deleting and Creating Documents in Typesense
Priyank asked for help with deleting and creating documents in Typesense and found the problem to be an issue with their own code. Jason offered support.
7
10mo
Solved
Deleting All Documents in Typesense Collection
Vikas wanted to delete all documents in a typesense collection. Kishore Nallan suggested using a range filter on a numerical field to match and delete the entire dataset.
3
32mo
Solved