api-clients-automation icon indicating copy to clipboard operation
api-clients-automation copied to clipboard

Documentation missing in Java documentation: how to clear an index before sending new data to Algolia

Open FDelporte opened this issue 2 years ago • 1 comments

Description

It's unclear now what is the best method to clear an index before sending new data.

I used this approach, but it's not clear to me if this will be executed in the correct order:

            List<BatchRequest> requests = new ArrayList<>();

            requests.add(new BatchRequest().setAction(Action.CLEAR));

            for (ContentSection section : sections) {
                requests.add(new BatchRequest()
                        .setAction(Action.ADD_OBJECT)
                        .setBody(section)
                );
            }

            BatchResponse response = client.batch(ALGOLIA_INDEX, new BatchWriteParams().setRequests(requests));

            client.waitForTask(ALGOLIA_INDEX, response.getTaskID());

Steps to reproduce

This page: https://api-clients-automation.netlify.app/docs/clients/guides/send-data-to-algolia

Environment

  • Java API

FDelporte avatar Dec 07 '22 15:12 FDelporte

Hey, thanks for reporting, the easiest way to remove all records is with:

UpdatedAtResponse response = client.clearObjects("myIndexName");
client.waitForTask("myIndexName", response.getTaskID());

We will add a page to the documentation :)

millotp avatar Dec 07 '22 15:12 millotp