What Meilisearch Does
- Instant Search: Sub-50ms search responses even on large datasets
- Typo Tolerance: Automatic handling of typos and misspellings
- Faceted Search: Filter by categories, prices, dates, and custom attributes
- Hybrid Search: Combine keyword search with AI embeddings for semantic understanding
- Synonyms: Define synonyms for better search results
- Ranking Rules: Customizable ranking with business logic
- Multi-Language: Built-in support for 20+ languages including Chinese, Japanese, Arabic
- Geosearch: Search by geographic distance and bounding box
- Index Management: Create, update, and delete indexes with REST API
- API Keys: Granular access control with scoped API keys
Architecture
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ Your App │────▶│ Meilisearch │────▶│ Local Disk │
│ (Search UI) │ │ Engine │ │ (LMDB) │
└──────────────┘ │ (Rust) │ └──────────────┘
└──────────────┘Meilisearch is a single binary written in Rust. No external dependencies — just a single process that stores data in an embedded LMDB database.
Self-Hosting
Docker Compose
services:
meilisearch:
image: getmeili/meilisearch:latest
ports:
- "7700:7700"
environment:
MEILI_MASTER_KEY: your-master-key-min-16-chars
MEILI_ENV: production
MEILI_NO_ANALYTICS: "true"
volumes:
- meili-data:/meili_data
restart: unless-stopped
volumes:
meili-data:Basic Usage
1. Create Index and Add Documents
# Add documents to an index
curl -X POST 'http://localhost:7700/indexes/products/documents'
-H "Authorization: Bearer your-master-key"
-H "Content-Type: application/json"
--data-binary '[
{
"id": 1,
"name": "iPhone 15 Pro",
"price": 999,
"brand": "Apple",
"tags": ["phone", "premium"]
},
{
"id": 2,
"name": "Samsung Galaxy S24",
"price": 899,
"brand": "Samsung",
"tags": ["phone", "android"]
}
]'2. Search
# Simple search
curl 'http://localhost:7700/indexes/products/search?q=iphone'
-H "Authorization: Bearer your-master-key"
# Advanced search with filters
curl -X POST 'http://localhost:7700/indexes/products/search'
-H "Authorization: Bearer your-master-key"
-H "Content-Type: application/json"
-d '{
"q": "phone",
"filter": "price < 1000 AND brand = "Apple"",
"sort": ["price:asc"],
"limit": 10,
"attributesToHighlight": ["name"]
}'3. Typo Tolerance in Action
Query: "iphne" → Finds "iPhone" (automatic typo correction)
Query: "samsong" → Finds "Samsung"
Query: "prroducts" → Finds "products"SDK Examples
JavaScript
import { MeiliSearch } from 'meilisearch';
const client = new MeiliSearch({
host: 'http://localhost:7700',
apiKey: 'your-master-key',
});
// Add documents
await client.index('products').addDocuments([
{ id: 1, name: 'iPhone 15', price: 999 },
]);
// Search
const results = await client.index('products').search('iphone', {
limit: 10,
filter: 'price < 1500',
});Python
import meilisearch
client = meilisearch.Client('http://localhost:7700', 'your-master-key')
# Add documents
client.index('products').add_documents([
{'id': 1, 'name': 'iPhone 15', 'price': 999}
])
# Search
results = client.index('products').search('iphone', {
'limit': 10,
'filter': 'price < 1500'
})Key Features
Hybrid Search (AI + Keyword)
{
"q": "comfortable running shoes",
"hybrid": {
"embedder": "openai",
"semanticRatio": 0.5
}
}Combines traditional keyword matching with AI semantic understanding for best results.
Faceted Search
{
"q": "phone",
"facets": ["brand", "price_range", "tags"]
}Response includes facet counts for building filter UIs.
Ranking Rules
{
"rankingRules": [
"words",
"typo",
"proximity",
"attribute",
"sort",
"exactness",
"popularity:desc"
]
}Instant Search UI
Use InstantMeilisearch for React/Vue/vanilla JS:
import { InstantSearch, SearchBox, Hits } from 'react-instantsearch-dom';
import { instantMeiliSearch } from '@meilisearch/instant-meilisearch';
const searchClient = instantMeiliSearch('http://localhost:7700', 'your-key');
function App() {
return (
<InstantSearch indexName="products" searchClient={searchClient}>
<SearchBox />
<Hits hitComponent={ProductHit} />
</InstantSearch>
);
}Meilisearch vs Alternatives
| Feature | Meilisearch | Typesense | Algolia | ElasticSearch |
|---|---|---|---|---|
| Open Source | Yes (MIT) | Yes (GPL) | No | Yes (Elastic/AGPL) |
| Setup | Single binary | Single binary | SaaS | Cluster |
| Typo tolerance | Built-in | Built-in | Built-in | Plugin |
| AI hybrid search | Yes | Yes | Yes | Yes (v8) |
| Faceted search | Yes | Yes | Yes | Yes |
| Geosearch | Yes | Yes | Yes | Yes |
| Language | Rust | C++ | N/A | Java |
| RAM per 1M docs | ~1GB | ~1GB | N/A | ~4GB+ |
| Pricing | Free | Free | $500+/mo | Free (self-host) |
常见问题
Q: Meilisearch 适合多大的数据集? A: 适合中小型数据集(几十万到几千万文档)。官方推荐单实例处理 10M 以下文档。对于亿级数据,ElasticSearch 或 Qdrant 更合适。
Q: 中文搜索效果如何? A: 非常好。Meilisearch 内置中文分词(jieba),对简体/繁体、混合中英文查询都有良好支持。无需额外配置。
Q: 和 Algolia 比主要区别? A: Algolia 是托管服务($$$),Meilisearch 可以自托管(免费)。功能相似,Meilisearch 的搜索速度与 Algolia 相当。对于成本敏感的项目,Meilisearch 是完美替代。
来源与致谢
- GitHub: meilisearch/meilisearch — 57K+ ⭐ | MIT
- 官网: meilisearch.com