使用本方法,可以触发强制合并操作。
默认情况下,ElasticSearch
会在后台周期性触发合并操作,因此不需要用户刻意使用本方法。
使用强制合并的弊端:
- 可能会产生大于5G的
segment
对象,而ElasticSearch
后台自动触发的合并操作会跳过此类大型segment
对象。 - 假如定期执行强制合并,将导致快照的成本增高,原因是强制合并产生的
segment
的变动,导致无法增量创建快照。
方法参数
max_num_segments
合并操作完成后,创建的segment
对象的数量。
当指定为1
时,表示完全合并。
未指定本参数时,表示仅当符合条件时,才会执行合并操作。
only_expunge_deletes
,默认值为false
。
true
,检查全部segment
对象,对于标记为删除记录的占比超出参数index.merge.policy.expunge_deletes_allowed
的segment
,执行合并操作。false
,不检查删除记录的占比。
wait_for_completion
,默认值为true
。
true
,表示同步调用,需要等待本次强制合并任务结束,调用才会返回。false
,表示异步调用,可以使用返回的任务标识来查询进度,但注意触发的任务不会被取消。假如有多个任务被触发,则会被调度器放在队列中,逐个执行。
注意only_expunge_deletes
和max_num_segments
不能同时使用。
相关参数
index.merge.policy.expunge_deletes_allowed
index
中已被标记为删除状态的记录的比例,百分数,默认值为10
。
当前only_expunge_deletes
取值为true
时使用。
使用样例
创建测试用的index
,命名为testindex_001
,命令样例,如下:
curl -X PUT "https://localhost:9200/testindex_001?pretty" --cacert $ES_HOME/config/certs/http_ca.crt -u "elastic:ohCxPH=QBE+s5=*lo7F9"
执行结果的样例,如下:
{
"acknowledged": true,
"shards_acknowledged": true,
"index": "testindex_001"
}
执行时指定index
的名称testindex_001
,命令样例,如下:
curl -X POST "https://localhost:9200/testindex_001/_forcemerge?pretty" --cacert $ES_HOME/config/certs/http_ca.crt -u "elastic:ohCxPH=QBE+s5=*lo7F9"
执行结果的样例,如下:
{
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
}
}
执行时不指定index
的名称,命令样例,如下:
curl -X POST "https://localhost:9200/_forcemerge?pretty" --cacert $ES_HOME/config/certs/http_ca.crt -u "elastic:ohCxPH=QBE+s5=*lo7F9"
执行结果的样例,如下:
{
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
}
}
执行时不指定index
的名称,异步调用,命令样例,如下:
curl -X POST "https://localhost:9200/_forcemerge?wait_for_completion=false&pretty" --cacert $ES_HOME/config/certs/http_ca.crt -u "elastic:ohCxPH=QBE+s5=*lo7F9"
执行结果的样例,如下:
{
"task" : "aKgBu7LgS9a6iPYH8n2JPw:103209"
}
相关资料
- ElasticSearch Force merge APIelasticsearch force merge api victoriametrics force merge elasticsearch merge elasticsearch专题api elasticsearch segments api cat elasticsearch plugins api cat elasticsearch management task api elasticsearch datafeeds api cat elasticsearch repositories api cat elasticsearch index api get