Meilisearch: A “Lightning-Fast” Search Engine to Replace Elasticsearch for Small and Mid-sized Projects

Database tutorial - IT technology blog
Database tutorial - IT technology blog

Tired of Elasticsearch’s bulkiness?

Installing Elasticsearch for a personal blog or a medium-sized e-commerce site is like using a sledgehammer to crack a nut. You have to wrestle with Java, dozens of complex YAML files, and RAM consumption reaching gigabytes just for a basic search bar. Meilisearch was created to solve that pain point. After 6 months of running it in production for several real-world projects, I can confirm that this is a “ready-to-use” search engine but with premium quality.

Written in Rust, Meilisearch is extremely lightweight. It focuses entirely on user experience with instant search-as-you-type capabilities and excellent typo-tolerance.

Deploy Meilisearch in 5 Minutes

Docker is the optimal choice to get started. It keeps your development environment clean and avoids cluttering your operating system.

1. Launch the Service

docker run -it --rm \
    -p 7700:7700 \
    -v $(pwd)/meili_data:/meili_data \
    getmeili/meilisearch:latest

Now, Meilisearch will be listening on port 7700. You can immediately access http://localhost:7700 to experience its highly intuitive Web UI management interface.

2. Indexing Your Data

Meilisearch uses a RESTful API standard, making integration effortless. You can use curl, Postman, or any HTTP library. For example, to save a list of IT articles:

curl \
  -X POST 'http://localhost:7700/indexes/posts/documents' \
  -H 'Content-Type: application/json' \
  --data-binary '[\
    {"id": 1, "title": "Basic Redis Guide", "category": "Database"},\
    {"id": 2, "title": "Python Programming for Beginners", "category": "Programming"}\
  ]'

3. Testing Search Speed

Try searching for the keyword “red”:

curl 'http://localhost:7700/indexes/posts/search?q=red'

The result is returned almost instantly. In my projects, latency is usually under 10ms for a database of about 50,000 records.

Why Meilisearch is a “Value for Money” Choice?

Many people often hesitate between Meilisearch and Elasticsearch. However, suitability is the deciding factor.

  • Resource Efficiency: Elasticsearch needs at least 2GB of RAM to run stably, while Meilisearch only consumes about 150MB for the same amount of data.
  • Effortless Configuration: Forget about complex concepts like Shards, Replicas, or Mapping. Everything is automated as much as possible.
  • Smart Typo Handling: If a user types “pyton”, they still get “Python” results. This typo-tolerance feature works by default without tiring configuration.
  • User Experience: Ultra-fast response speeds help create search suggestion boxes that update as soon as the user touches a key.

When working with Meilisearch, JSON data preparation is mandatory. If you need to quickly convert old CSV data to JSON, I suggest the tool at toolcraft.app/en/tools/data/csv-to-json. It runs entirely in the browser, ensuring customer data safety.

Optimizing Search Results with Ranking Rules

Although the defaults are excellent, you should still fine-tune Ranking Rules for even better results.

Custom Result Sorting

Meilisearch prioritizes results based on keyword matching and keyword position. To prioritize the newest articles, simply add a sorting rule by timestamp:

curl \
  -X POST 'http://localhost:7700/indexes/posts/settings' \
  -H 'Content-Type: application/json' \
  --data-binary '{\
    "rankingRules": [\
      "words",\
      "typo",\
      "proximity",\
      "attribute",\
      "sort",\
      "exactness",\
      "published_at:desc"\
    ]\
  }'

Security with API Keys

Never leave Meilisearch “open” in production. Use a MEILI_MASTER_KEY. The system will automatically generate a Default Search Key (safe to expose on the client side) and a Default Admin Key (keep this server-side only).

Lessons Learned After 6 Months in Production

Actual operation is quite different from theory. Here are 4 points I’ve gathered:

1. Note on Disk Space

Meilisearch uses LMDB to achieve extreme speeds. In return, the database file can grow 3-5 times larger than the raw JSON data. Ensure your server’s disk has plenty of storage space.

2. Don’t Index Indiscriminately

Only index fields that need to be searched, such as title or content. Fields like image links or metadata should only be included in attributesToRetrieve to increase processing speed and save memory.

3. Vietnamese Language Support

Meilisearch’s tokenization supports Vietnamese quite well. However, if you want precise search results for accented/unaccented words in specific contexts, you should look further into stopWords and synonyms.

4. Backup Strategy

The Dumps feature is the easiest way to backup. It compresses the entire index into a single file. When moving servers, just start Meilisearch with this dump file and you’re done.

# Create dump file
curl -X POST 'http://localhost:7700/dumps'

# Restore data
./meilisearch --import-dump /path/to/data.dump

Conclusion

Meilisearch is the perfect missing piece for small and medium-sized applications. It’s lightweight, fast, and extremely easy to deploy. If you are building an IT blog or an e-commerce website, try installing Meilisearch today. You will be amazed at the speed it brings to your users.

Share: