elasticsearch判斷索引是否存在


一、判斷索引是否存在 
指定索引名,判斷指定的索引是否存在集群中

 /** * 判斷指定的索引名是否存在 * @param indexName 索引名 * @return 存在:true; 不存在:false; */ public boolean isExistsIndex(String indexName){ IndicesExistsResponse response = getClient().admin().indices().exists( new IndicesExistsRequest().indices(new String[]{indexName})).actionGet(); return response.isExists(); }

二、判斷索引指定類型是否存在

/** * 判斷指定的索引的類型是否存在 * @param indexName 索引名 * @param indexType 索引類型 * @return 存在:true; 不存在:false; */ public boolean isExistsType(String indexName,String indexType){ TypesExistsResponse response = getClient().admin().indices() .typesExists(new TypesExistsRequest(new String[]{indexName}, indexType) ).actionGet(); System.out.println(FastJSONHelper.serialize(response)); return response.isExists(); } 輸出的JSON格式內容: { "context":{ "empty":true }, "contextEmpty":true, "exists":true, "headers":[] }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM