Elasticsearch中的设置refresh_interval

在 Elasticsearch 中,refresh_interval 是一个 索引级别 的设置,用于控制 从内存缓冲区把新增/更新的文档刷到文件系统缓存(使其可搜索)的频率


🔍 一句话解释

它决定了 多久把"刚写入的数据"变成"立即可搜索的数据"


⚙️ 默认值

复制代码
"refresh_interval": "1s"
  • 默认每 1秒 执行一次 refresh。

  • 也就是说,默认情况下,新写入的文档最多延迟1秒就能被搜索到


🧪 参数说明

含义
"1s" 每1秒刷新一次(默认)
"30s" 每30秒刷新一次,降低I/O,提升写入吞吐量
"-1" 禁用自动刷新 ,需要手动调用 POST /my_index/_refresh 才能搜索到新数据

🧰 设置方法

创建索引时设置:
复制代码
PUT /my_index
{
  "settings": {
    "refresh_interval": "30s"
  }
}
动态修改(无需重启):
复制代码
PUT /my_index/_settings
{
  "refresh_interval": "30s"
}

✅ 使用场景建议

场景 推荐值 原因
实时搜索要求高(如电商搜索) "1s" 或更短 保证数据可见性
日志/批处理写入 "30s" 或更长 减少I/O,提升写入性能
大批量导入数据(如重建索引) 设置为 "-1",导入完成后手动 refresh 最大化写入吞吐量

🧠 小提示

  • 调大 refresh_interval 可以显著提升 bulk 写入速度,但会牺牲"实时性"。

  • 如果你在做 全量重建索引大批量导入 ,建议临时设置为 "-1",导入完再改回来。

相关推荐
Java 码思客20 小时前
【ElasticSearch从入门到架构师】第1章:ElasticSearch 核心认知与行业定位
大数据·elasticsearch·搜索引擎
serve the people1 天前
Elasticsearch(5) i want to monitor the es health from a http api
大数据·http·elasticsearch
Taerge01101 天前
Doris, StarRocks, ClickHouse, Hologres, ES 对比,选型建议
大数据·clickhouse·elasticsearch
serve the people2 天前
Elasticsearch(1) could you tell me how to use es if i am a beginner
大数据·elasticsearch·jenkins
一个儒雅随和的男子2 天前
Elasticsearch出现深度分页问题怎么解决?
大数据·elasticsearch·搜索引擎
serve the people2 天前
Elasticsearch(3) show me some examples
大数据·elasticsearch·jenkins
是一个Bug2 天前
Elasticsearch 保姆级入门:从“找文件”到“秒级搜索”
大数据·elasticsearch·搜索引擎
serve the people2 天前
Elasticsearch(4) show me some more advanced content
大数据·elasticsearch·jenkins
fangdengfu1233 天前
ES分析系统各个服务日志占用量
java·前端·elasticsearch
兄台の请冷静3 天前
Linux 安装es
linux·elasticsearch·jenkins