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",导入完再改回来。

相关推荐
Elasticsearch1 天前
对 OpenTelemetry Kafka 接收器的两项改动,避免一个缓慢的租户拖住其他租户
elasticsearch
全栈陈序员2 天前
Git】从入门到精通(八)—— git log:查看提交历史
大数据·git·elasticsearch
Percep_gan2 天前
Linux中安装gitea,很详细
linux·elasticsearch·gitea
木棉软糖3 天前
5 步确认 TiDB 历史抽数的 Logstash 有没有真的写进 ES
elasticsearch·oracle·tidb
全栈陈序员3 天前
【Git】从入门到精通(十一)—— git reset 三种模式详解
git·elasticsearch
Elasticsearch3 天前
Elasticsearch:稠密向量字段类型
elasticsearch
全栈陈序员4 天前
【Git】从入门到精通(五)—— git add:将文件加入暂存区
大数据·git·elasticsearch
全栈陈序员4 天前
【Git】从入门到精通(七)—— git status:查看仓库状态
大数据·git·elasticsearch
fengye2071614 天前
第三章 编译cpython
大数据·elasticsearch·搜索引擎
Elasticsearch4 天前
使用 Qoder 将 CSV 文件导入 Elasticsearch
elasticsearch