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