If you are using an Instance with a Docker InstantApp, run docker -v
to make sure that the Docker engine is already installed. The current Docker engine version should display.
Deploying Meilisearch on a Scaleway Instance
- meilisearch
- search
- full-text
- instance
Meilisearch is an open-source search engine that provides instant and relevant search results from large collections of data. Meilisearch is particularly useful for applications that require fast and efficient search capabilities, such as e-commerce sites, documentation search, and any platform where users need to quickly find relevant information from a large dataset.
This tutorial shows you how to deploy a Meilisearch search engine on a Scaleway Instance.
Before you start
To complete the actions presented below, you must have:
- A Scaleway account logged into the console
- Owner status or IAM permissions (specifically InstancesFullAccess) allowing you to perform actions in the intended Organization
- An SSH key
- An Instance with the Docker InstantApp or with the Docker Engine installed
Connecting to your Instance and starting Meilisearch
-
Open a terminal and connect to your Instance using SSH. Replace
<INSTANCE_IP>
with your Instance’s IP (Instances > Overview > Flexible IP > the first IP address that displays in the list).ssh root@<INSTANCE_IP>Tip -
In the same terminal, generate a master key for Meilisearch. This key will secure your Meilisearch instance.
export MEILI_MASTER_KEY=$(openssl rand -base64 16) -
Run the following command to display the master key:
echo $MEILI_MASTER_KEYImportantCopy and save your master key as you will need it in the next steps.
-
Run the MeiliSearch container using Docker. This command sets up Meilisearch to store data persistently on the volume located at
$(pwd)/meili_data:/meili_data
on your Instance.docker run -d -p 7700:7700 -v $(pwd)/meili_data:/meili_data -e $MEILI_MASTER_KEY getmeili/meilisearch:v1.9 -
Check that the container is running:
docker psYou should see an output similar to the following:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES0432254e4d64 getmeili/meilisearch:v1.9 "tini -- /bin/sh -c …" 56 minutes ago Up 56 minutes 0.0.0.0:7700->7700/tcp, :::7700->7700/tcp flamboyant_dewdneyTipYou can stop the Meilisearch container using
docker container stop <container_name>
. -
Use the following command to check that Meilisearch is running.
curl -X GET 'http://localhost:7700/version' -H 'Authorization: Bearer '$MEILI_MASTER_KEYYou should see an output similar to the following:
{"commitSha": "0df84bbba7db46680e83843dd6454257161a282f","commitDate": "2024-06-27T12:00:00Z","pkgVersion": "aaaaaa"}
Accessing Meilisearch remotely
- Open a new terminal and export your environment variables. Make sure that you replace
{INSTANCE_PUBLIC_DNS}
and{MEILI_MASTER_KEY}
with your own variables.Your command should look like the following:export INSTANCE_PUBLIC_DNS={INSTANCE_PUBLIC_DNS}export MEILI_MASTER_KEY={MEILI_MASTER_KEY}export INSTANCE_PUBLIC_DNS=a3dc5b0e-5c5c-4ac4-91fb-1447b5c23b57.pub.instances.scw.cloudexport MEILI_MASTER_KEY=LtRrsh68IdT2jKDH5DdXhA== - Run the following command to access Meilisearch remotely:
curl -X GET 'http://'$INSTANCE_PUBLIC_DNS':7700/version' -H 'Authorization: Bearer '$MEILI_MASTER_KEY
You can also open your browser at http://{INSTANCE_PUBLIC_DNS}:7700/health
since you do not need an API key to access the /health
endpoint.
If you have created your Instance within a Private Network or if you are using a specific security group configuration, you must allow TCP traffic on port 7700
for your Instance to access your Meilisearch container remotely. See our dedicated documentation on how to use security groups and how to configure a Public Gateway for more information.
Creating an index and adding data to it
-
In the same terminal as the previous steps, paste the following command to create a new index named
movies
:curl -X POST 'http://'$INSTANCE_PUBLIC_DNS':7700/indexes' \-H 'Content-Type: application/json' \-H 'Authorization: Bearer '$MEILI_MASTER_KEY \--data-binary '{"uid": "movies","primaryKey": "id"}' -
Add sample data to the
movies
index. In this case, we are adding 2 movies.curl -X POST 'http://'$INSTANCE_PUBLIC_DNS':7700/indexes/movies/documents' \-H 'Content-Type: application/json' \-H 'Authorization: Bearer '$MEILI_MASTER_KEY \--data-binary '[{"id": 1,"title": "The Enigma of Elysia","overview": "In a world where magic and technology coexist, a mysterious artifact known as the Elysia Stone is stolen from the royal palace."},{"id": 2,"title": "A Shattered Mirror","overview": "In a world where dreams are reflected in a magical mirror, a young man named Orion discovers that his reflection has been shattered."}]'An output similar to the following should display:
{"taskUid":1,"indexUid":"movies","status":"enqueued","type":"documentAdditionOrUpdate","enqueuedAt":"2024-07-24T12:32:54.678571608Z"}root@scw-lucid-satoshi:~# -
Search for the term
mystery
in themovies
index:curl -X POST 'http://'$INSTANCE_PUBLIC_DNS':7700/indexes/movies/search' \-H 'Content-Type: application/json' \-H 'Authorization: Bearer '$MEILI_MASTER_KEY \--data-binary '{ "q": "mystery" }'Documents containing the term (or close semantic variations of the term) should display in the output:
{"hits":[{"id":1,"title":"The Enigma of Elysia","overview":"In a world where magic and technology coexist, a mysterious artifact known as the Elysia Stone is stolen from the royal palace."}],"query":"mystery","processingTimeMs":4,"limit":20,"offset":0,"estimatedTotalHits":1}
Going further
-
Learn more about Meilisearch APIs and features
-
Secure your deployment:
- Encrypt traffic in transit to Meilisearch by setting up SSL
- Move your Instance inside a Private Network if you do not want it to be exposed publicly on the internet
- Configure regular data backups using Meilisearch Snapshots or Instances snapshots
-
Fine-tune deployment configuration such as Instance type or disk size, from the Scaleway console, the Scaleway API, CLI or Terraform.
Troubleshooting
If you encounter any issues, check that you meet all the requirements listed at the beginning of this page. Also, verify that your Instance accepts connections from your computer. To do so, you can configure security groups or a Public Gateway on the Private Network your Instance belongs to.