ElasticSearch合并Segment

作用:

      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 高级优化

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容