1. 程式人生 > >elasticsearch Flush Refresh JAVA API

elasticsearch Flush Refresh JAVA API

/**
 * <pre>
 * 索引重新整理方法
 *@param indexName 重新整理索引
 *@return 是否重新整理成功
 * <pre>
 */
public boolean indexRefresh(String ...indexName ) {
    logger.info("ES索引開始重新整理,索引名為:"+indexName);
    Client client = getClient();
    try {
        RefreshResponse response =  client.admin().indices()
                  .refresh(new
RefreshRequest(indexName)) .actionGet(); if(response.getShardFailures().length == response.getTotalShards()){ logger.info("ES索引重新整理失敗"+response.getShardFailures()); return false; }else if(response.getShardFailures().length>0){ logger.info("ES索引重新整理部分分片失敗"
+response.getShardFailures()); } logger.info("ES索引重新整理成功"); return true; }catch (Exception e) { logger.error("ES重新整理失敗", e); return false; } }
/**
 * <pre>
 * 索引Flush方法
 *@param indexName 重新整理索引
 *@return 是否重新整理成功
 * <pre>
 */
public boolean
indexFlush(String ...indexName ) { logger.info("ES索引名開始重新整理,索引名為:"+indexName); Client client = getClient(); try { FlushResponse response = client.admin().indices() .flush(new FlushRequest(indexName)) .actionGet(); //輸出json格式的響應資訊 logger.info(FastJSONHelper.serialize(response)); if(response.getShardFailures().length == response.getTotalShards()){ logger.info("ES索引重新整理失敗"+response.getShardFailures()); return false; }else if(response.getShardFailures().length>0){ logger.info("ES索引重新整理部分分片失敗"+response.getShardFailures()); } logger.info("ES索引重新整理成功"); return true; }catch (Exception e) { logger.error("ES重新整理失敗", e); return false; } }