Elasticsearch 缓存相关(qbit)
文章目录
前言
- 本文对
Elasticsearch7.17 适用 Elasticsearch主要有 3 种缓存:fields cache、query cache、request cache3 种 cache 的配置状况都可以用命令查看
# 集群 GET _cluster/settings?include_defaults&flat_settings # 索引 GET my-index/_settings?include_defaults&flat_settings
Field Data Cache
- 官方文档:Field data cache settings
Field data cache包含fielddata和global ordinals,两者都主要用于聚合。fielddata 和 doc_value 的相同点
都要创建正排索引,数据结构类似于列式存储 都是为了可以聚合,排序之类的操作fielddata 和 doc_value 的不同点
# 存储索引数据的方式不一样: fielddata: heap 内存存储;doc_values: OS Cache + 磁盘存储 # 针对的类型,也不一样 fielddata 主要针对的是分词字段(text);doc_values 针对大是不分词字段(keyword、int 等) # 是否开启 fielddata 默认不开启;doc_values 默认是开启- 静态配置项
indices.fielddata.cache.size是一个节点级的配置,默认无限制 查看集群的
fielddataGET _stats/fielddata?human查看所有节点的
fielddataGET _nodes/stats/indices/fielddata?human查看单个节点
mzjaGC52QXeaHBXcJ1jp3g的fielddataGET _nodes/mzjaGC52QXeaHBXcJ1jp3g/stats/indices/fielddata?human查看单个索引的
request_cacheGET my_index/_stats/fielddata?human
Shard Request Cache
- 官方文档:Shard request cache settings
request_cache特点request_cache 是一个“分片级”的缓存,shard 是缓存 key 的一部分 request_cache 主要用于 size=0 的查询,如纯聚合查询(aggs)、hits.total 和 suggestions request_cache 是自动失效的,失效时间就是索引的 refresh 时间(index.refresh_interval),失效的前提是分片内容确实发生了变化 request_cache 缓存的默认大小是 JVM 堆内存的 1%,可以通过参数 indices.request.cache.size 手动设置- 静态配置项
indices.requests.cache.size是一个节点级的配置,默认为1% 查看集群的
request_cacheGET _stats/request_cache?human查看所有节点的
request_cacheGET _nodes/stats/indices/query_cache?human查看单个节点
mzjaGC52QXeaHBXcJ1jp3g的request_cacheGET _nodes/mzjaGC52QXeaHBXcJ1jp3g/stats/indices/request_cache?human查看单个索引的
request_cacheGET my_index/_stats/request_cache?human- 应注意在请求语句中使用
request_cache=true参数。官方文档:https://www.elastic.co/guide/en/elasticsearch/reference/7.17/...
Node Query Cache
- 官方文档:Node query cache settings
query_cache是 Node 级别的缓存,主要用于缓存filter上下文返回的结果- 默认情况下,
query_cache最多可容纳 10000 个查询,最多占 JVM 堆内存的 10%。 indices.queries.cache.count和indices.queries.cache.size都是节点级别的配置,不能动态修改,需要修改配置文件并重启集群查看集群的
query_cacheGET _stats/query_cache?human查看所有节点的
query_cacheGET _nodes/stats/indices/query_cache?human查看单个节点
mzjaGC52QXeaHBXcJ1jp3g的query_cacheGET _nodes/mzjaGC52QXeaHBXcJ1jp3g/stats/indices/query_cache?human查看单个索引的
query_cacheGET my_index/_stats/query_cache?human
缓存清理
官方文档:Clear cache API
不分缓存类型清理缓存
# 清理集群所有缓存 POST _cache/clear # 清理单个索引缓存 POST my_index/_cache/clear按缓存类型清理缓存
清理
fielddata缓存POST _cache/clear?fielddata=true POST my-index/_cache/clear?fielddata=true清理
query缓存POST _cache/clear?query=true POST my-index/_cache/clear?query=true清理
request缓存POST _cache/clear?request=true POST my-index/_cache/clear?request=true
参考文献
- Elasticsearch2.x 三种缓存介绍:Query Cache、Request Cache、Fielddata Cache
- 张超:扒一扒查询缓存的裤子
- ElasticSearch中doc values和fielddata
- ElasticSearch 缓存概览
- Elasticsearch的Query Cache 知识梳理
本文出自 qbit snap

评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论