基于ES7.7 官方文档
内容包括:
- 清空缓存 ( Clear cache )
- 更新索引以让新文档可以被搜索 ( Refresh )
- 将内存缓冲区中的文档写入磁盘 ( Flush )
- 同步Flush ( Synced flush ) 7.6版本被弃用
- 强制合并 ( Force merge )
1. 清空缓存 (Clear cache API)ES中refresh和flush的区别: 参考官方博客 https://blog.csdn.net/UbuntuTouch/article/details/103641544
清空一个或多个索引的缓存。官方文档
POST /路径参数/_cache/clear
(可选, string) 支持多个逗号连接的多个索引名称或者通配符表达式。
请求参数allow_no_indices
(可选, bool) 默认true。如果设置为true, 则当全部使用通配符*、_all只检索不存在(missing)或者已关闭(closed)的索引(或索引别名)时,不会抛出错误。
expand_wildcards
(可选, string) 通配符查询时的范围限制。支持多个条件以逗号分割。默认open。
- all: 匹配open和closed的索引, 包括隐藏的.
- open: 默认, 表示只查询开放中的索引
- closed: 只匹配closed的索引
- hidden: 隐藏的(hidden)索引, 必须和open/closed联合使用.
- none: 不接受通配符.
fielddata
(可选, bool) 如果为true, 则清空字段的缓存。与参数fields一起使用,仅清空指定字段的缓存。
fields
(可选, string) 支持多个字段名的逗号拼接。与参数fielddata一起使用,仅清空指定字段的缓存。默认是所有字段。
不支持对象和字段别名
index
(可选, string) 支持多个索引名称的逗号拼接。
ignore_unavailable
(可选, bool) 如果为true,则 返回数据中不会包含missing或closed的索引。默认false,查询时只要有一个索引不存在,就会返回404并抛出错误信息。
query
(可选, bool) 如果为true,清空查询缓存(query cache)。
request
(可选, bool) 如果为true,清空请求缓存(request cache)。
几个栗子1、清空指定类型的缓存 (Clear a specific cache)
默认情况下,这个/_cache/clear API会清空所有缓存。如果只想清空指定的缓存, 可以把下面的几个参数设置为true:
- fielddata
- query
- request
# 仅清空字段的缓存 POST //_cache/clear?fielddata=true # 仅清空查询缓存 POST / /_cache/clear?query=true # 仅清空请求缓存 POST / /_cache/clear?request=true
2、清空指定字段的缓存
使用参数fields来指定要清空的字段,支持多个字段的逗号连接
# 仅清空字段 field1 和 field2 的缓存 POST //_cache/clear?fields=field1,field2
3、清空多个索引的缓存
#清空索引 index1 和 index2 的所有缓存 POST /index1,index2/_cache/clear
4、清空所有索引的缓存
POST /_cache/clear # 下面两个不常用 POST /_all/_cache/clear POST _refresh
2. 刷新当前集群的所有索引
POST /_refresh # 下面两个不常用 POST /_all/_refresh POST _flush
3、 flush当前集群的所有索引
POST /_flush # 下面两种不常用 POST /_all/_flush POST _forecemerge
3、强制合并所有索引
POST /_forcemerge # 下面两个不常用 POST /_all/_forcemerge POST /*/_forcemerge
4、基于时间的索引 (Time-based indices)
强制合并对基于时间的索引很有用, 特别是使用rollover时。 在这些情况下,每个索引只在一段时间内接收索引流量。 一旦索引不再接收到写操作,它的分片就可以被强制合并为一个段。
# 把索引强制合并为一个段 POST /logs-000001/_forcemerge?max_num_segments=1
This can be a good idea because single-segment shards can sometimes use simpler and more efficient data structures to perform searches.
这会是一个好主意,因为只有一个段的分片有时可以使用更简单和高效的数据结构来执行搜索。
last updated at 2021/11/8 22:55



