Elasticsearch Java API之清空索引
2015-08-05 22:09
597 查看
package com.nerve.core.test; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.util.Properties; import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse; import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse; import org.elasticsearch.client.Client; import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.common.transport.InetSocketTransportAddress; public class ClusterManager { private static Client javaClient = null; private static Properties properties = null; public static Client getJavaClient() { if (javaClient == null) { try { String urlstr = getIp(); URL url = new URL(urlstr); javaClient = new TransportClient() .addTransportAddress(new InetSocketTransportAddress(url .getHost(), 9300)); } catch (Exception e) { e.printStackTrace(); } } return javaClient; } public static Properties getProperties() throws IOException { if (properties == null) { properties = new Properties(); InputStream inputStream = ClusterManager.class .getResourceAsStream("/sysconfig.properties"); System.out.println(inputStream); properties.load(inputStream); } return properties; } public static String getIp() { String es_cluster_master_ip = "http://10.0.0.113:9200"; try { es_cluster_master_ip = getProperties().getProperty( "es_cluster_master_ip"); } catch (IOException e) { e.printStackTrace(); } System.out.println(es_cluster_master_ip); return es_cluster_master_ip; } public static void main(String[] args) throws Exception { Client client=getJavaClient(); ClusterStateResponse response = client.admin().cluster() .prepareState() .execute().actionGet(); //获取所有索引 String[] indexs=response.getState().getMetaData().getConcreteAllIndices(); for (String index : indexs) { System.out.println(index+" delete");// //清空所有索引。 DeleteIndexResponse deleteIndexResponse = client.admin().indices() .prepareDelete(index) .execute().actionGet(); System.out.println(deleteIndexResponse.getHeaders()); } //client.admin().cluster(). //http://10.0.0.101:9200/_status //http://10.0.0.101:9200/_status //indices } }
相关文章推荐
- JAVA监听
- Java心得7
- Spring+Shiro案例分析
- springMvc 将对象json返回时自动忽略掉对象中的特定属性的注解方式
- java 中的观察者模式
- java读取目录下(包括子目录)的所有文件
- Spring(一):AOP
- struts2二次上传图片缓存问题
- Java中的linkedList
- java 序列化ID的作用
- java模式—装饰者模式
- Spring的IOC
- mybatis与spring的整合
- 获取请求参数
- Java IO
- java大数模板
- Java练习题(四)
- java多线程之volatile关键字
- JAVA学习第十五天
- LeetCode:242 Valid Anagram Java