The generated API clients are a work in progress, you can also find our stable clients on the Algolia documentation.

Skip to main content

Send data to Algolia

Algolia doesn’t search directly into your own data source. For data to be searchable, you need to send it to Algolia’s servers.

This happens right after retrieving your data from your data source and reformatting it. Once your data is ready, you can push it to Algolia using the batch method.

Sending your data

caution

If the data you are sending is more than 1000 records at once, we recommend you to use our chunked batch solution instead.

Before sending anything to Algolia, you need to retrieve your data. You can do this in several ways, in our case we will pick it from the source code directly.

import { searchClient } from '@algolia/client-search';

const client = searchClient('YOUR_APP_ID', 'YOUR_API_KEY');

const response = await client.batch({
indexName: '<YOUR_INDEX_NAME>',
batchWriteParams: {
requests: [
{ action: 'addObject', body: { key: 'bar', foo: '1' } },
{ action: 'addObject', body: { key: 'baz', foo: '2' } },
],
},
});

// use typed response
console.log(response);

await client.waitForTask({ indexName: '<YOUR_INDEX_NAME>', taskID: response.taskID });