Overview
This guide will take you step-by-step through the creation of a Node.js script to upload Algolia index data to Meilisearch. You can also skip directly to the finished script. The migration process consists of three steps:- Export your data stored in Algolia
- Import your data into Meilisearch
- Configure your Meilisearch index settings (optional)
This guide was tested with the following package versions:
node.js:16.16algoliasearch:4.13meilisearch-js:0.27.0meilisearch:0.28
Export your Algolia data
Initialize project
Start by creating a directoryalgolia-meilisearch-migration and generating a package.json file with npm:
script.js file:
Install dependencies
To get started, you’ll need two different packages. The first isalgoliasearch, the JavaScript client for the Algolia API, and the second is meilisearch, the JavaScript client for the Meilisearch API.
Create Algolia client
You’ll need your Application ID and Admin API Key to start the Algolia client. Both can be found in your Algolia account. Paste the below code inscript.js:
APPLICATION_ID and ADMIN_API_KEY with your Algolia application ID and admin API key respectively.
Replace INDEX_NAME with the name of the Algolia index you would like to migrate to Meilisearch.
Fetch data from Algolia
To fetch all Algolia index data at once, use Algolia’sbrowseObjects method.
batch callback method is invoked on each batch of hits and the content is concatenated in the records array. We will use records again later in the upload process.
Import your data into Meilisearch
Create Meilisearch client
Create a Meilisearch client by passing the host URL and API key of your Meilisearch instance. The easiest option is to use the automatically generated admin API key.MEILI_HOST,MEILI_API_KEY, and MEILI_INDEX_NAME with your Meilisearch host URL, Meilisearch API key, and the index name where you would like to add documents. Meilisearch will create the index if it doesn’t already exist.
Upload data to Meilisearch
Next, use the Meilisearch JavaScript methodaddDocumentsInBatches to upload all your records in batches of 100,000.
Finished script
Configure your index settings
Meilisearch’s default settings are designed to deliver a fast and relevant search experience that works for most use-cases. To customize your index settings, we recommend following this guide. To learn more about the differences between settings in Algolia and Meilisearch, read on.Index settings vs. search parameters
One of the key usage differences between Algolia and Meilisearch is how they approach index settings and search parameters. In Algolia, API parameters is a flexible category that includes both index settings and search parameters. Many API parameters can be used both at indexing time—to set default behavior—or at search time—to override that behavior. In Meilisearch, index settings and search parameters are two distinct categories. Settings affect all searches on an index, while parameters affect the results of a single search. Some Meilisearch parameters require index settings to be configured beforehand. For example, you must first configure the index settingsortableAttributes to use the search parameter sort. However, unlike in Algolia, an index setting can never be used as a parameter and vice versa.