在 Elasticsearch(ES)中,“优化索引”通常指提升写入性能、查询性能、降低存储成本、提升稳定性。下面从索引设计、写入优化、查询优化、存储与集群层面系统性说明。
PUT /my_index
{
"settings": {
"number_of_shards": 3,
"number_of_replicas": 1
}
}
"dynamic": false
"enabled": false
或
"index": false
| 场景 | 推荐 |
|---|---|
| 精确匹配 | keyword |
| 全文搜索 | text |
| 时间 | date |
| 数值范围 | integer / long / scaled_float |
| 不需要聚合 | text + index:false |
_source如果不需要回查原始数据:
"_source": {
"enabled": false
}
或只保留必要字段:
"_source": {
"includes": ["id", "name"]
}
_bulk大批量导入时:
PUT /my_index/_settings
{
"number_of_replicas": 0
}
导入完成后再恢复。
默认 1s,写入多时可调大:
PUT /my_index/_settings
{
"refresh_interval": "30s"
}
"index.translog.durability": "async"
❌
"wildcard": { "name": "abc*" }
✅ 使用 keyword + prefix
filter 不计算评分,可缓存"bool": {
"filter": [
{ "term": { "status": "active" } }
]
}
text 字段上聚合keyword"_source": ["id", "title"]
POST /my_index/_forcemerge?max_num_segments=1
✅ 适合日志、历史数据
❌ 不要对正在写入的索引操作
自动:
"rollover": {
"max_size": "50gb",
"max_age": "30d"
}
CPUHeapSegment 数Refresh / Merge 时间❌ 分片越多越快
❌ 所有字段都 text
❌ 一直 refresh=0
❌ 不做 ILM
如果你愿意,可以告诉我:
我可以给你针对性的索引模板和参数配置。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。