Why Developers Choose Meilisearch: Lightweight Instant Search Engine Guide

This article introduces Meilisearch as a lightweight, fast alternative to Elasticsearch, detailing its features, Docker installation, and RESTful API usage for index management, settings configuration, document CRUD operations, and advanced search with pagination, sorting, and filtering.

macrozheng
macrozheng
macrozheng
Why Developers Choose Meilisearch: Lightweight Instant Search Engine Guide

Introduction

Meilisearch is a lightweight search engine that supports RESTful search APIs and has garnered over 50k stars on GitHub. Its goal is to provide a search solution suitable for all users, delivering fast and precise search experiences. Key features include:

Fast search: results within 50 milliseconds.

Instant search: results appear as you type.

Typo tolerance: accurate results even with misspelled keywords.

Comprehensive language support: optimized for Chinese.

Highly customizable search and indexing: tailor search behavior to your needs.

RESTful API support.

SDKs for multiple languages: Java, JavaScript, Go, Python, and others.

The following demo illustrates the instant search speed.

Meilisearch instant search demo
Meilisearch instant search demo

Installation

Deploying Meilisearch with Docker is convenient; we will use this method.

Pull the Meilisearch Docker image: docker pull getmeili/meilisearch:v1.13 Run the Meilisearch container:

docker run -p 7700:7700 --name meilisearch \
-e MEILI_ENV='development' \
-v /mydata/meiliData:/meili_data \
-d getmeili/meilisearch:v1.13

After successful startup, access the Mini Dashboard at http://192.168.3.101:7700.

Meilisearch Mini Dashboard
Meilisearch Mini Dashboard

Usage

We will now explain Meilisearch usage via its RESTful API.

Index Operations

In Meilisearch, an index is a collection of documents, analogous to a table in MySQL.

Download the official demo dataset from Meilisearch documentation:

https://www.meilisearch.com/docs/learn/self_hosted/getting_started_with_self_hosted_meilisearch

.

Demo data download page
Demo data download page

Upload the data to your server and import it into Meilisearch using curl:

curl \
 -X POST '{{MEILISEARCH_URL}}/indexes/movies/documents?primaryKey=id' \
 -H 'Content-Type: application/json' \
 --data-binary @movies.json

You can now see the data in the Mini Dashboard, for example searching for Transformers.

Search results for Transformers in Mini Dashboard
Search results for Transformers in Mini Dashboard

List all indexes:

curl \
 -X GET '{{MEILISEARCH_URL}}/indexes'

You can also use Postman for API calls.

Postman GET indexes request
Postman GET indexes request

Delete an index:

curl \
 -X DELETE '{{MEILISEARCH_URL}}/indexes/movies'

Settings Operations

Index settings is a JSON object containing many options that define Meilisearch's search behavior, similar to a table schema in MySQL.

Retrieve current settings:

curl \
 -X GET '{{MEILISEARCH_URL}}/indexes/movies/settings'

Postman response:

Postman GET settings response
Postman GET settings response

Modify settings to make title and release_date sortable, and genres and release_date filterable:

curl \
 -X PATCH '{{MEILISEARCH_URL}}/indexes/movies/settings' \
 -H 'Content-Type: application/json' \
 --data-binary '{
   "sortableAttributes": [
     "title",
     "release_date"
   ],
   "filterableAttributes": [
     "genres",
     "release_date"
   ]
 }'

Postman response after update:

Postman PATCH settings response
Postman PATCH settings response

Document Operations

In Meilisearch, a document is an object with multiple attributes, analogous to a row in a MySQL table.

Add a document:

curl \
 -X POST '{{MEILISEARCH_URL}}/indexes/movies/documents' \
 -H 'Content-Type: application/json' \
 --data-binary '{
   "id": 1,
   "title": "Transformers Test",
   "overview": "Young teenager, Sam Witwicky becomes involved in the ancient struggle between two extraterrestrial factions of transforming robots...",
   "genres": [
     "Adventure",
     "Science Fiction",
     "Action"
   ],
   "poster": "https://image.tmdb.org/t/p/w500/6eehp9I54syN3x753XMqjKz8M3F.jpg",
   "release_date": 1182902400
 }'

Postman response:

Postman POST document response
Postman POST document response

Retrieve a document:

curl \
 -X GET '{{MEILISEARCH_URL}}/indexes/movies/documents/1'

Postman response:

Postman GET document response
Postman GET document response

Update a document:

curl \
 -X PUT '{{MEILISEARCH_URL}}/indexes/movies/documents' \
 -H 'Content-Type: application/json' \
 --data-binary '[
   {
     "id": 1,
     "title": "Transformers Update"
   }
 ]'

Delete a document:

curl \
 -X DELETE '{{MEILISEARCH_URL}}/indexes/movies/documents/1'

Data Search

Now we demonstrate how to search data with Meilisearch.

Basic search:

curl \
 -X POST '{{MEILISEARCH_URL}}/indexes/movies/search' \
 -H 'Content-Type: application/json' \
 --data-binary '{ "q": "Transformers" }'

Postman response:

Postman basic search response
Postman basic search response

Paginated search (offset 0, limit 5):

curl \
 -X POST '{{MEILISEARCH_URL}}/indexes/movies/search' \
 -H 'Content-Type: application/json' \
 --data-binary '{ "q": "Transformers","offset": 0,"limit": 5 }'

Postman response:

Postman paginated search response
Postman paginated search response

Search with sorting (by release_date descending):

curl \
 -X POST '{{MEILISEARCH_URL}}/indexes/movies/search' \
 -H 'Content-Type: application/json' \
 --data-binary '{ "q": "Transformers","offset": 0,"limit": 5,"sort": ["release_date:desc"] }'

Postman response:

Postman sorted search response
Postman sorted search response

Search with filtering (genres = Action OR Adventure):

curl \
 -X POST '{{MEILISEARCH_URL}}/indexes/movies/search' \
 -H 'Content-Type: application/json' \
 --data-binary '{ "q": "Transformers","offset": 0,"limit": 5,"sort": ["release_date:desc"],"filter":"genres = Action OR genres = Adventure" }'

Postman response:

Postman filtered search response
Postman filtered search response

Summary

This article walked through Meilisearch's search capabilities. Compared to Elasticsearch, Meilisearch requires minimal hardware configuration and delivers very fast search speeds. Interested developers are encouraged to try it.

Project Repository

https://github.com/meilisearch/meilisearch
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Dockersearch engineElasticsearchREST APIfull-text searchMeilisearchinstant searchtypo tolerance
macrozheng
Written by

macrozheng

Dedicated to Java tech sharing and dissecting top open-source projects. Topics include Spring Boot, Spring Cloud, Docker, Kubernetes and more. Author’s GitHub project “mall” has 50K+ stars.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.