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.
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.
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.13After successful startup, access the Mini Dashboard at http://192.168.3.101:7700.
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.
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.jsonYou can now see the data in the Mini Dashboard, for example searching for Transformers.
List all indexes:
curl \
-X GET '{{MEILISEARCH_URL}}/indexes'You can also use Postman for API calls.
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:
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:
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:
Retrieve a document:
curl \
-X GET '{{MEILISEARCH_URL}}/indexes/movies/documents/1'Postman 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:
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:
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:
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:
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/meilisearchSigned-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
