Required API Key: any key with the addObject ACL

Method signature
index.saveObject(...).waitTask();
index.saveObjects(...).waitTask();
index.partialUpdateObject(...).waitTask();
index.partialUpdateObjects(...).waitTask();
index.replaceAllObjects(...).waitTask();
index.deleteObject(...).waitTask();
index.deleteObjects(...).waitTask();
index.deleteBy(...).waitTask();
index.clearObjects(...).waitTask();

index.setSettings(...).waitTask();

index.saveSynonym(...).waitTask();
index.saveSynonyms(...).waitTask();
index.replaceAllSynonyms(...).waitTask();
index.deleteSynonym(...).waitTask();
index.clearSynonyms(...).waitTask();

index.saveRule(...).waitTask();
index.saveRules(...).waitTask();
index.replaceAllRules(...).waitTask();
index.deleteRule(...).waitTask();
index.clearRules(...).waitTask();


client.moveIndex(...).waitTask();
client.copyIndex(...).waitTask();
client.copyRules(...).waitTask();
client.copySynonyms(...).waitTask();
client.copySettings(...).waitTask();

client.addApiKey(...).waitTask();
client.updateApiKey(...).waitTask();
client.deleteApiKey(...).waitTask();
client.multipleBatch(...).waitTask();

About this method # A

Wait for a task to complete to ensure synchronized index updates.

All Algolia write operations are asynchronous. When you make a request for a write operation, for example, to add or update records in your index, Algolia creates a task on a queue and returns a taskID. The task itself runs separately, depending on the server load. You can wait for a write operation to complete by using the task’s taskID and the waitTask method.

Examples # A

Wait until a new object is added to an index#

1
2
3
4
5
6
7
BatchIndexingResponse resp = index.saveObject(
  new Contact().setFirstname("Jimmie").setLastname("Barninger")
);

// All objects implementing the AlgoliaWaitableResponse interface
// Can be awaited with the .waitTask() method
resp.waitTask();

If you want to ensure multiple objects have been indexed, you must check all taskIDs.

Wait for indexing of a new object and send extra http header#

1
2
3
4
5
6
7
8
BatchIndexingResponse resp = index.saveObject(
  new Contact().setFirstname("Jimmie").setLastname("Barninger"),
  new RequestOptions().addExtraHeader("X-Algolia-User-ID", "user123")
);

// All objects implementing the AlgoliaWaitableResponse interface
// Can be awaited with the .waitTask() method
resp.waitTask();

Parameters # A

taskID #
type: string
Required

taskID of the indexing task to wait for.

requestOptions #
type: list
default: No requestOptions
Optional

A list of request options to send along with the query.

Response # A

This method doesn't return a response.

Did you find this page helpful?