elasticsearch清空索引缓存 java api

参考链接:https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-clearcache.html
应用场景:

1.在进行测试时,如果想知道真实的查询情况,或者缓存占用的太多,需要清理缓存时,就需要先清除内存中的缓存信息;
2.当内存使用超过自己设置的阀值,没法自动清理时,可以强制清理;
以下为清空缓存方法:

 /**
     * 清空指定索引的缓存
     * @param indexName 索引名
     * @return  清空结果
     */
    public boolean clearIndicesCache(String indexName){
        ClearIndicesCacheResponse  response = null;
        try {
            response = getClient().admin().indices()
                    .clearCache(new ClearIndicesCacheRequest(indexName)
                    .fieldDataCache(true)
                    .filterCache(true)
                    .idCache(true)
                    ).actionGet();
            System.out.println(FastJSONHelper.serialize(response));
            if (response.getFailedShards()>0) {
                return false;
            }
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

CURL方式:
curl -XPOST ‘http://localhost:9200/twitter/_cache/clear
twitter为indexName,默认情况下会清空所有缓存.可以设置filter,fielddata,query_cache,或者id_cache为true,如我们只清空filter缓存命令:
curl -XPOST ‘http://localhost:9200/twitter/_cache/clear?filter=true
fields参数可以指定删除特定的字段,如:
curl -XPOST ‘http://localhost:9200/twitter/_cache/clear?filter=true&fields=cphm,cplx
filter缓存大约会在60秒内清空完成,而不是立即的。

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值