Mass Delete with filter

I am using Algolia for search purposes and we got a huge pile of records. We want to delete some records and have decided to delete records that are older than X date.

First I was using this

const records = [];
const deleteRecordsBeforeDateAlgolia = (date) => {
    let client;

    *****

    const index = client.initIndex('function_message');
    //get the records before the given date
    try {
        index.search('',{
            filters: `time_stamp < ${date}`
        }).then(({hits}) => {
            if(hits.length > 0) {
                for (const hit of hits) {
                    index.deleteObject(hit.objectID);
                    records.push(hit.objectID);
                }
            }
            if(hits.length === 0) {
                console.log(`Deleted ${records.length} records`);
            } else {
                deleteRecordsBeforeDateAlgolia(date);
            }
        });
    } catch (err) {
        console.error(err);
    }
};

but I realized this isnt that optimized + will be very slow when deleting on prod. Can you tell me how I can get huge amounts of data with a filter (timestamp in this case) and then delete all of them? also want all of this to be synchronous

Hi! For retrieving large amounts of records for a batch operation like this, you’ll want browseObjects instead of a searching.

You can include a filter for the data range. You can also limit the response to just the objectIDs, then pass the array of objectIds to deleteObjects for batch deletion.