Typesense Cloud Issue: Unable to Delete Documents by ID
TLDR Ellen had trouble using Typesense Cloud's filter_by
option to delete documents by id. Jason solved this by suggesting to remove double-quotes around IDs in filter_by
clause.


Oct 07, 2022 (11 months ago)
Ellen
01:28 AMfilter_by
option. For whatever reason, I can’t seem to get it to work when filtering by the id
field. The same syntax seems to work when I use a different field. Will post an example in the thread.Ellen
01:30 AMnum_deleted
of 0 and does not remove the documents:this.client.collections("collection").documents().delete({
filter_by:
'id:=["id1", "id2", "id3"]',
});
Ellen
01:32 AMthis.client.collections("collection").documents().delete({
filter_by:
'name:=["name1", "name2"]',
});
Ellen
01:33 AMKishore Nallan
01:54 AMEllen
04:02 AMKishore Nallan
06:05 AMid
field in the filter_by
clause and it works for me. Can you please post a small reproduceable code snippet that I can try?
Ellen
09:06 PM const collectionName = 'delete-test-collection';
// create collection
const schema: CollectionCreateSchema = {
name: collectionName,
fields: [
{ name: 'id', type: 'string' },
{ name: 'name', type: 'string' },
{ name: 'createdAt', type: 'int64' },
{ name: '.*', type: 'auto' },
],
default_sorting_field: 'createdAt',
};
await this.client.collections().create(schema);
const documents = [
{
id: 'a620b2c0-7b19-4d38-813c-b26efe37ccce',
name: 'doc1',
createdAt: 1626895838564,
},
{
id: 'cbf07f65-18d3-455f-aab1-4fd98c21a740',
name: 'doc2',
createdAt: 1626837810820,
},
{
id: '6aeb7d7a-9d9e-4849-a2d6-b7af75725ea7',
name: 'doc3',
createdAt: 1626883734635,
},
];
await this.client
.collections(collectionName)
.documents()
.import(documents, { action: 'upsert' });
const deleteByIdRes = await this.client
.collections(collectionName)
.documents()
.delete({
filter_by:
'id:=["a620b2c0-7b19-4d38-813c-b26efe37ccce", "cbf07f65-18d3-455f-aab1-4fd98c21a740"]',
});
console.log(`${deleteByIdRes.num_deleted} documents deleted by id`);
const deleteByNameRes = await this.client
.collections(collectionName)
.documents()
.delete({
filter_by: 'name:=["doc1", "doc2"]',
});
console.log(`${deleteByNameRes.num_deleted} documents deleted by name`);
Ellen
09:07 PM0 documents deleted by id
2 documents deleted by name
Oct 11, 2022 (11 months ago)
Ellen
04:42 PMOct 12, 2022 (11 months ago)
Jason
03:50 PMIn the
filter_by
clause, the IDs, should not be surrounded by double-quotes.If I remove those double-quotes, it works as expected:
const deleteByIdRes = await client
.collections(collectionName)
.documents()
.delete({
filter_by:
'id:=[a620b2c0-7b19-4d38-813c-b26efe37ccce, cbf07f65-18d3-455f-aab1-4fd98c21a740]',
})```
2 documents deleted by id0 documents deleted by name```
Ellen
05:39 PM
Typesense
Indexed 2764 threads (79% resolved)
Similar Threads
Issue with Typesense Schema and Ruby Client
Mateo faces issues while creating a schema and using Ruby client for Typesense. Jason suggests using a new field instead of 'id' and provides assistance for Ruby client errors.
Understanding Document ID Fields and Rectifying Duplicate Document Error
John queried about understanding document ID fields and fixed a duplication issue with guidance from Jason. They discovered a bug preventing document deletion due to a URL encodable character, with John opening a GitHub issue for it.


Resolving Document Export & Batch Deletion Issues
Dui had trouble exporting a document and wanted batch deletion assistance. Kishore Nallan fixed the export issue, upgraded their cluster manually and suggested using `delete by query`.


Slow Document Deletion in Typesense Database
Robert inquired about speeding up deletes in Typesense. Robert agreed to file a detailed bug report following the discussion with Kishore Nallan who is investigating a possible bug causing the delay in document deletion.


Fixing Multiple Document Retrieval in Typesense
Phil needed an efficient way to retrieve multiple documents by id. Kishore Nallan proposed a solution available in a pre-release build. After some bug fixing regarding id matching by Jason and Kishore Nallan, Phil successfully tested the solution.


