Skip to content

Instantly share code, notes, and snippets.

@softquantum
Forked from eliyas5044/MeiliSearch.md
Created November 6, 2023 01:32
Show Gist options
  • Save softquantum/96034e1be440692ad32999e0fe8c41e5 to your computer and use it in GitHub Desktop.
Save softquantum/96034e1be440692ad32999e0fe8c41e5 to your computer and use it in GitHub Desktop.
MeiliSearch installation and configuration.

MeiliSearch

⚡ Lightning Fast, Ultra Relevant, and Typo-Tolerant Search Engine 🔍

Github | Website

Get Started

  1. Install MeiliSearch
  2. Version
  3. Indexes
  4. Tasks
  5. Documents
  6. Search
  7. Settings

Install MeiliSearch

  • Login as Super User
sudo su
  • Install MeiliSearch (Ubuntu)
curl -L https://install.meilisearch.com | sh
  • Move the MeiliSearch binary to your system binaries
mv ./meilisearch /usr/bin/
  • Create a service file
    • Specify Host, e.g. --http-addr 127.0.0.1:7700
    • Specify Environment, e.g. --env production
    • Specify Master Key, e.g. --master-key MasterKey
    • Specify Database Path, e.g. --db-path /root/data.ms
cat << EOF > /etc/systemd/system/meilisearch.service
[Unit]
Description=MeiliSearch
After=systemd-user-sessions.service

[Service]
Type=simple
ExecStart=/usr/bin/meilisearch --http-addr 127.0.0.1:7700 --env production --master-key MasterKey --db-path /root/data.ms

[Install]
WantedBy=default.target
EOF
  • Enable and start service
systemctl enable meilisearch

systemctl start meilisearch

systemctl status meilisearch

Version

curl \
  -X GET 'http://127.0.0.1:7700/version' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer MasterKey' | python3 -mjson.tool

Indexes

Get Indexes

curl \
  -X GET 'http://127.0.0.1:7700/indexes' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer MasterKey' | python3 -mjson.tool

Create Index

curl \
  -X POST 'http://127.0.0.1:7700/indexes' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer MasterKey' \
  --data-binary '{
    "uid": "users",
    "primaryKey": "id"
  }' | python3 -mjson.tool

Delete Index

curl \
  -X DELETE 'http://127.0.0.1:7700/indexes/users' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer MasterKey' | python3 -mjson.tool

Tasks

Get Tasks

curl \
  -X GET 'http://127.0.0.1:7700/tasks' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer MasterKey' | python3 -mjson.tool

Get Index Tasks

curl \
  -X GET 'http://127.0.0.1:7700/indexes/users/tasks' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer MasterKey' | python3 -mjson.tool

Documents

Get Documents

curl \
  -X GET 'http://127.0.0.1:7700/indexes/users/documents' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer MasterKey' | python3 -mjson.tool

Add Documents

curl \
  -X POST 'http://127.0.0.1:7700/indexes/users/documents' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer MasterKey' \
  --data-binary '[
    {
      "id": 1,
      "name": "Eliyas Hossain",
      "email" "eliyas.devxhub@gmail.com"
    }
  ]' | python3 -mjson.tool

Search

curl \
  -X POST 'http://127.0.0.1:7700/indexes/users/search' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer MasterKey' \
  --data-binary '{ "q": "eliyas" }' | python3 -mjson.tool

Settings

Get Settings

curl \
  -X GET 'http://127.0.0.1:7700/indexes/users/settings' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer MasterKey' | python3 -mjson.tool

Update Displayed Settings

curl \
  -X POST 'http://127.0.0.1:7700/indexes/users/settings/displayed-attributes' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer MasterKey' \
  --data-binary '[
    "id",
    "name",
    "email",
    "avatar"
  ]' | python3 -mjson.tool

Update Searchable Settings

curl \
  -X POST 'http://127.0.0.1:7700/indexes/users/settings/searchable-attributes' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer MasterKey' \
  --data-binary '[
    "name",
    "email"
  ]' | python3 -mjson.tool

Update Filterable Settings

curl \
  -X POST 'http://127.0.0.1:7700/indexes/users/settings/filterable-attributes' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer MasterKey' \
  --data-binary '[
    "id",
    "email"
  ]' | python3 -mjson.tool

Update Sortable Settings

curl \
  -X POST 'http://127.0.0.1:7700/indexes/users/settings/sortable-attributes' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer MasterKey' \
  --data-binary '[
    "id",
    "name"
  ]' | python3 -mjson.tool

Update Ranking Rules Settings

curl \
  -X POST 'http://127.0.0.1:7700/indexes/users/settings/ranking-rules' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer MasterKey' \
  --data-binary '[
    "words",
    "sort",
    "typo",
    "proximity",
    "attribute",
    "exactness"
  ]' | python3 -mjson.tool
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment