问题
Elasticsearch 开发时可能会遇到查询结果与实际数据不符的情况,这个时候我们不妨清理缓存试试!
code
public boolean clearIndicesCache(String indexName){
try {
ClearIndicesCacheRequest request = new ClearIndicesCacheRequest(indexName);
//Set the query flag to true
request.queryCache(true);
// Set the fielddata flag to true
request.fieldDataCache(true);
// Set the request flag to true
request.requestCache(true);
ClearIndicesCacheResponse response = restHighLevelClient.indices().clearCache(request, RequestOptions.DEFAULT);
if (response.getFailedShards()>0) {
return false;
}
return true;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
官网说明:https://www.elastic.co/guide/en/elasticsearch/client/java-rest/7.4/java-rest-high-clear-cache.html