Guides / Sending and managing data / Send and update your data

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. If you need more guidance with this step, please read the Format and Structure Your Data guide.

Once your data is ready, you can push it to Algolia using the saveObjects method.

Quickstart

If you want to get started with the most common indexing operations, explore the quickstart samples on GitHub. These are self-contained code samples that you can run directly from your code editor.

Required credentials

To push data to Algolia, you need an Application ID and a valid API key with the right access level. You can find them in the Algolia dashboard in the API Keys section. These credentials let you connect to Algolia and perform operations on your data.

Application ID

Your Application ID is what Algolia uses to identify your app, where all your indices live.

API key

The Admin API key is the one you need to create, update, and delete records. This is the most sensitive key, as it provides full control of all your indices and data. Make sure to keep it secret and secure, don’t release it to anyone, and only use it in back-end code.

For added security, it’s better not to use your Admin API key directly to handle indices, but generate more restrictive keys from it and use them instead.

Guides API Keys

Setting up the API client

First, you need to install and set up your API client. For installation instructions, head over to the installation guide for your language.

1
2
3
4
5
6
7
8
9
10
11
12
// composer autoload
require __DIR__ . '/vendor/autoload.php';

// if you are not using composer
// require_once 'path/to/algoliasearch.php';

$client = \Algolia\AlgoliaSearch\SearchClient::create(
  'YourApplicationID',
  'YourAdminAPIKey'
);

$index = $client->initIndex('your_index_name');

Fetching your data

Before sending anything to Algolia, you need to retrieve your data. You can do this in several ways, depending on the nature of your application. Here are potential examples:

From a database

1
2
3
4
5
6
function fetchDataFromDatabase() {
  $actors = // Fetch data from your database
  return $actors;
}

$records = fetchDataFromDatabase();

From a file

You can use this actors dataset to test this out.

1
$records = json_decode(file_get_contents('actors.json'), true);

From the source code directly

Only use this method for exploration purposes, or if you have a small amount of data.

1
2
3
4
$records = [
  ['name' => 'Tom Cruise'],
  ['name' => 'Scarlett Johansson']
];

Send the data to Algolia

Once the records are ready, you can then push them to Algolia using the saveObjects method.

1
$index->saveObjects($records, ['autoGenerateObjectIDIfNotExist' => true]);

Batching your records

For performance reasons, you should send several records at once instead of one by one. If you have many records to index, you should send them in batches.

Once you’re done, don’t forget to configure relevance settings.

Did you find this page helpful?