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

Algolia doesn’t directly search your data sources. Instead, you upload the parts of your data that are relevant for search to Algolia. Algolia stores this data in an index: a data structure optimized for fast search.

For more information about preparing your data for indexing, see Format and structure your data.

Required credentials

To send data to Algolia, you need an Application ID and a valid API key (with addObjects permission). You can find them in the API Keys section of Algolia’s dashboard.

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 complete control of all your indices and data. Keep it secret and secure, don’t release it to anyone, and only use it in backend code.

For added security, don’t use your Admin API key to handle indices directly; instead, use it to generate keys with more restrictions and use them.

Guides API keys

Set up the API client

First, you need to install and set up your API client. For installation instructions, go to the API client documentation for your programming language:

PHP
Ruby
JavaScript
Python
Swift
Kotlin
.NET
Java
Scala

After installing the API client, you can initialize it and connect to Algolia:

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',
  'YourWriteAPIKey'
);

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

Fetch 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 push them to Algolia using the saveObjects method.

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

Send your data in batches

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, remember to configure relevance settings.

Did you find this page helpful?