zoukankan      html  css  js  c++  java
  • elasticsearch client java 简单code 应用

    package com.kele,xuebi;
    
    import java.net.InetAddress;
    import java.net.UnknownHostException;
    
    import org.elasticsearch.action.index.IndexResponse;
    import org.elasticsearch.client.Client;
    import org.elasticsearch.client.transport.TransportClient;
    import org.elasticsearch.common.settings.Settings;
    import org.elasticsearch.common.transport.InetSocketTransportAddress;
    
    public class CreateIndex {
    
    	public static void main(String[] args) throws UnknownHostException {
    		// TODO Auto-generated method stub
    		
    		//client 配置参考官方资料链接 
    		//https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/transport-client.html
    		
    		//my-application  本名字跟 /opt/elasticsearch-2.2.0/config/elasticsearch.yml 中配置的集群参数名字相同 cluster.name: my-application
    		
    		Settings  settings = Settings.settingsBuilder().put("cluster.name", "my-application").build();
    
    		Client client = TransportClient.builder().settings(settings).build()
    		.addTransportAddresses(new InetSocketTransportAddress(InetAddress.getByName("bigdataspark"), 9300))
    		.addTransportAddresses(new InetSocketTransportAddress(InetAddress.getByName("bigdatacloud"), 9300))
    		.addTransportAddresses(new InetSocketTransportAddress(InetAddress.getByName("bigdatastorm"), 9300));
    		
    		IndexResponse actionGet = client.prepareIndex("shuiguo101", "friut", "1").setSource().execute().actionGet();
    		
    		System.out.println(actionGet);
    		client.close();
    			
    	}
    
    }
    

    这玩意不简单!!!!!!


  • 相关阅读:
    POJ-2096-Collecting Bugs(概率DP)
    2019ICPC南京网络赛总结
    LOJ-6285-数列分块入门9
    LOJ-6284-数列分块入门8
    LOJ-6283-数列分块7
    bzoj2049: [Sdoi2008]Cave 洞穴勘测
    bzoj1010: [HNOI2008]玩具装箱toy
    bzoj1597: [Usaco2008 Mar]土地购买
    bzoj1233: [Usaco2009Open]干草堆tower 单调队列优化dp
    bzoj2442&&codevs4654 单调队列优化dp
  • 原文地址:https://www.cnblogs.com/TendToBigData/p/10501399.html
Copyright © 2011-2022 走看看