作用:
1.释放已删除但未释放磁盘的数据
2.提高查询速度
API
参数详解
POST /my-index-000001/_forcemerge
http://localhost:9200/my-index-000001/_forcemerge ?max_num_segments =1&only_expunge_deletes=false&wait_for_merge=false&flush=false
JAVA方式:
@Resource
ElasticsearchTemplate elasticsearchTemplate
private void merge(String... indexName) {
IndicesAdminClient indices = elasticsearchTemplate.getClient().admin().indices();
logger.info("ES索引开始优化,索引名为:" + indexName);
ForceMergeRequestBuilder forceMergeRequestBuilder = indices.prepareForceMerge(indexName)
.setOnlyExpungeDeletes(false)
.setMaxNumSegments(1);
ActionFuture<ForceMergeResponse> responseActionFuture = indices.forceMerge(forceMergeRequestBuilder.request());
logger.info("ES索引优化成功");
}
参考:Elasticsearch 高级优化