一、判斷索引是否存在
指定索引名哆姻,判斷指定的索引是否存在集群中
/**
* 判斷指定的索引名是否存在
* @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":[]
}