为什么我们从 Elasticsearch 迁移到了 Meilisearch
Why We Migrated from Elasticsearch to Meilisearch
| Alex Chen | 2026-07-27T19:37:04
运维了两年的 ES 集群终于扛不住了,我们决定迁移到 Meilisearch。这篇文章分享了决策过程和迁移经验。
Sharing the decision-making process and migration experience of moving from Elasticsearch to Meilisearch after two years.
## 受够了 ES 先说说我们为什么要换。用了两年 ES,最大的痛点不是性能,而是**运维成本**。 三个节点的 ES 集群,吃掉了 48GB 内存。隔三差五 GC 导致查询超时,分片迁移的时候整个集群卡住。每次升级版本都像在拆弹——Breaking Changes 比 changelog 长。 我们的数据量其实不大,总共也就 200 万条文档,纯文本搜索,不需要复杂的聚合分析。用 ES 就像用大炮打蚊子。 ## 为什么选 Meilisearch? 调研了几个替代品: | 方案 | 优点 | 缺点 | |------|------|------| | Meilisearch | 开箱即用,资源占用低 | 不支持复杂聚合 | | Typesense | 性能好,支持地理搜索 | 文档少,社区小 | | Zinc | Go 写的,轻量 | 功能太少 | | OpenSearch | ES 兼容 | 运维复杂度没变 | 最终选了 Meilisearch,原因很简单: 1. **单二进制部署**:下载一个文件就能跑,不需要 JVM,不需要集群 2. **资源占用极低**:200 万文档只用了 1.2GB 内存,ES 要 16GB+ 3. **中文搜索支持好**:内置了 jieba 分词,不需要额外装插件 4. **Typo tolerance**:用户打错字也能搜到结果,这个功能开箱即用 5. **RESTful API 简单**:比 ES 的 DSL 简单太多 ## 迁移过程 ### 数据导出 ```python # 从 ES 导出数据 from elasticsearch import Elasticsearch, helpers es = Elasticsearch(['http://es-node:9200']) # scroll API 批量导出 docs = helpers.scan(es, index='products', query={"query": {"match_all": {}}}) ``` ### 数据导入 ```python import meilisearch client = meilisearch.Client('http://localhost:7700', 'master-key') index = client.index('products') # 批量导入,每批 1000 条 batch = [] for doc in docs: batch.append(doc['_source']) if len(batch) >= 1000: index.add_documents(batch) batch = [] ``` 200 万条文档,导入花了 12 分钟。相比之下,ES 建索引加调优 mapping 的时间不知道花了多少个小时。 ### 搜索接口改造 ```python # ES 的查询 result = es.search(index='products', body={ "query": { "multi_match": { "query": keyword, "fields": ["name^3", "description"], "type": "best_fields" } } }) # Meilisearch 的查询 —— 简洁太多了 result = index.search(keyword, { 'attributesToSearchOn': ['name', 'description'], 'limit': 20 }) ``` ## 踩坑 1. **排序字段要提前声明**:Meilisearch 不像 ES 可以对任意字段排序,需要在 settings 里配置 `sortableAttributes` 2. **没有聚合功能**:如果你需要 facet 统计或 aggregation,Meilisearch 的 faceting 能力比 ES 弱很多 3. **大数据量有上限**:单个索引官方建议不超过 1000 万条,再大需要分索引 ## 迁移后的效果 - 内存:48GB → 1.2GB - 搜索延迟:P99 从 200ms 降到 30ms - 部署复杂度:3 节点集群 → 单进程 - 运维工作量:从每周花半天处理 ES 问题到基本不用管 如果你的场景和我们类似——数据量不大、主要是全文搜索、不需要复杂聚合——强烈推荐试试 Meilisearch。
## Why We Left Elasticsearch After two years, the main pain point wasn't performance but operational overhead. A 3-node ES cluster consuming 48GB RAM for just 2 million documents, with frequent GC pauses and painful version upgrades. ## Why Meilisearch Single binary deployment, 1.2GB RAM for 2M documents (vs 16GB+ on ES), built-in Chinese tokenization, typo tolerance out of the box, and a much simpler API. ## Migration Exported from ES using scroll API, imported to Meilisearch in batches - 2M documents in 12 minutes. Search API refactoring was straightforward due to Meilisearch's simpler query syntax. ## Results Memory dropped from 48GB to 1.2GB. P99 latency improved from 200ms to 30ms. Deployment simplified from 3-node cluster to single process. Operational overhead nearly eliminated.