首页/数据/NoSQL 速查/慢查询与慢索引日志配置
本包目录(322 条)
MongoDB99 条
Elasticsearch89 条
ClickHouse56 条时序与列式28 条选型与架构50 条

慢查询与慢索引日志配置

慢日志按耗时阈值记录检索与写入请求:可在索引级设置 warn/info/debug/trace 四档阈值;日志输出位置由节点 log4j2 配置决定。

NoSQL 速查数据更新于 2026-10-12
索引级设置index.search.slowlog.threshold.query.*、index.search.slowlog.threshold.fetch.*、index.indexing.slowlog.threshold.index.*
日志输出config/log4j2.properties 里配置 slowlog 对应 logger 与文件名
默认值阈值默认 -1 表示关闭;开启时显式设置时长如 5s

示例

示例
PUT /my-index/_settings
{
  "index": {
    "search.slowlog.threshold.query.warn": "10s",
    "search.slowlog.threshold.query.info": "5s",
    "search.slowlog.threshold.fetch.warn": "1s",
    "indexing.slowlog.threshold.index.info": "5s"
  }
}
慢日志包含查询主体与 query/fetch 耗时分解,是优化查询语句的主要依据;日志本身也占 IO,阈值不要过低。

易错点

  • 只改阈值不改 log4j2 时日志不会落到预期文件,排查前先确认日志目录中有对应文件
  • search 慢日志分成 query 与 fetch 两段,只看总耗时无法判断瓶颈在哪一段

数据来源与参考

  • Elasticsearch Guide: Slow log
​‌‌​​‌​​​‌‌​‌‌‌‌​‌‌​​​‌‌​‌‌‌​​‌‌​​‌​‌‌‌​​‌‌‌​​​‌​‌‌​‌​​‌​‌‌‌​​​‌​‌‌​‌​​‌​‌‌​​​‌‌​‌‌‌​‌​​​‌‌​‌‌‌‌​​‌​‌‌‌​​‌‌​​​‌‌​‌‌​‌‌‌‌​‌‌​‌‌​‌