Update MeiliSearch
I am using MeiliSearch for the Wannabes framework that I created, which indexes all the snippets and makes the search super fast.
I am also using Laravel Forge, this is how I provisioned MeiliSearch, but doing it this way, it is not clear how to keep MeiliSearch Updated. I hope this guide can help with that.
Although this guide is created specifically with MeiliSearch using Laravel Forge in mind, the process should be the same for other installs.
It does however assume that:
- An IP Address is specified to listen on,
- MeiliSearch runs as a service, and
- A Master Key is set within the service.
- You are logged into the server running MeiliSearch
Set some variables
This is useful for copy / paste of commands.
Store Master Key in a variable
masterKey=`grep -o "master-key\s[a-zA-Z0-9]*" \
/etc/systemd/system/meilisearch.service \
| cut -d" " -f2`
Store current listening IP address in a variable, we want to keep this the same.
meiliUrl=`grep -o "http-addr\s[\.:0-9]*" \
/etc/systemd/system/meilisearch.service \
| cut -d" " -f2`
Confirm variables.
echo $masterKey
echo $meiliUrl
Current Version
Just to get and make a note of the current version to compare to after upgrade.
curl -s -X GET "http://$meiliUrl/version" \
--header "X-Meili-API-Key: $masterKey" | jq
jq
is optional, but renders json nicely in the terminal and can be installed using most package managers. I am running on Ubuntu, soapt install jq
does the trick.
{
"commitSha": "928930ddd552596f51280a17c143cf38079cdea9",
"commitDate": "2021-09-13T10:17:10+00:00",
"pkgVersion": "0.22.0"
}
Store the pkgVersion
from the version output in a variable, it will be used later.
meiliVersion="0.22.0"
Current Indexes
Optional, but useful to see what the indexes currently are within MeiliSearch.
curl -s -X GET "http://$meiliUrl/indexes" \
--header "X-Meili-API-Key: $masterKey" | jq
[
{
"uid": "dev_snippets",
"name": "dev_snippets",
"createdAt": "2021-09-29T05:54:22.878069498Z",
"updatedAt": "2021-10-19T04:53:07.067189244Z",
"primaryKey": "id"
},
{
"uid": "pentester_snippets",
"name": "pentester_snippets",
"createdAt": "2021-09-29T05:54:31.368331867Z",
"updatedAt": "2021-10-19T04:55:03.885423646Z",
"primaryKey": "id"
}
]
Prepare for Upgrade
Before upgrading, dumps need to be created as databases are not compatible across versions. Any database created by MeiliSearch v0.X
can only be read by that version.
Create dump
curl -s -X POST "http://$meiliUrl/dumps" \
--header "X-Meili-API-Key: $masterKey" | jq
{
"uid": "20211027-051152103",
"status": "in_progress",
"startedAt": "2021-10-27T05:11:52.103832404Z"
}
Store the uid
from the dumps output in a variable
dumpsUid="20211027-051152103"
Check the status of the dump using the dump's uid
from above
curl -s -X GET "http://$meiliUrl/dumps/$dumpsUid/status" \
--header "X-Meili-API-Key: $masterKey" | jq
{
"uid": "20211027-051152103",
"status": "done",
"startedAt": "2021-10-27T05:11:52.103832404Z",
"finishedAt": "2021-10-27T05:11:55.391049878Z"
}
Dumps will live in /dumps/
with the $dumpsUid.dump
as the name.
ls /dumps/
20210929-054047423.dump 20211027-051152103.dump
Stop MeiliSearch
Once the dump process is complete, stop Meilisearch
sudo service meilisearch stop
Backup
Just in case, move the current data directory as a backup. I move the data directory using the current version appended to the directory name.
sudo mv /root/data.ms/ /root/data.ms.$meiliVersion/
Install MeiliSearch
This command will install the latest version
curl -L <https://install.meilisearch.com> | sh
After installation completes, move the binary to the correct location
sudo mv meilisearch /usr/bin/meilisearch
Confirm version
meilisearch -V
meilisearch-http 0.23.1
Import the dumps
Make sure to import the correct date's dumps. P.s. it should be in the $dumpsUid
variable.
sudo /usr/bin/meilisearch \
--env production \
--http-addr $meiliUrl \
--master-key $masterKey \
--db-path /root/data.ms \
--import-dump /dumps/$dumpsUid
This will run for a bit, but will soon indicate that the import is complete but will remain in a running state. Stop MeiliSearch using ^C
[2021-10-27T05:20:47Z INFO meilisearch_lib::index_controller::dump_actor] Loading dump from 2021-10-27 05:11:52.106080030 UTC, dump database version: 0.22.0, dump version: V2
[2021-10-27T05:20:48Z INFO meilisearch_lib::index_controller::dump_actor::loaders::v3] Loading dump from 2021-10-27 05:11:52.106080030 UTC, dump database version: 0.22.0, dump version: V3
[2021-10-27T05:20:56Z INFO meilisearch_lib::index_controller::dump_actor::loaders::v3] Loading indexes.
888b d888 d8b 888 d8b .d8888b. 888
8888b d8888 Y8P 888 Y8P d88P Y88b 888
88888b.d88888 888 Y88b. 888
888Y88888P888 .d88b. 888 888 888 "Y888b. .d88b. 8888b. 888d888 .d8888b 88888b.
888 Y888P 888 d8P Y8b 888 888 888 "Y88b. d8P Y8b "88b 888P" d88P" 888 "88b
888 Y8P 888 88888888 888 888 888 "888 88888888 .d888888 888 888 888 888
888 " 888 Y8b. 888 888 888 Y88b d88P Y8b. 888 888 888 Y88b. 888 888
888 888 "Y8888 888 888 888 "Y8888P" "Y8888 "Y888888 888 "Y8888P 888 888
Database path: "/root/data.ms"
Server listening on: "<http://10.106.0.3:7700>"
Environment: "production"
Commit SHA: "2e2eeb0a424408e27f4223e58afec303c53e1419"
Commit date: "2021-10-12T14:47:06+00:00"
Package version: "0.23.1"
Thank you for using MeiliSearch!
Start MeiliSearch Service
Once the import is complete, start the MeiliSearch service.
sudo service meilisearch start
Conclusion
That is currently my process for updating MeiliSearch, I am sure there will be changes to this once the MeiliSearch Team releases version 1.0, so keep an eye out for that.
If you enjoyed the post, please consider to subscribe so that you receive future content in your inbox :)
Psssst, worried about sharing your email address and would rather want to hide it? Consider using a service I created to help with that: mailphantom.io
Also, if you have any questions, comments, or suggestions please feel free to Contact Me.