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();
    			
    	}
    
    }
    

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


  • 相关阅读:
    约瑟夫问题
    十点半
    鹊桥相会
    C语言实验——数日子
    汉诺塔
    读入字符串
    C语言实验——各位数字之和排序
    数据结构实验之链表五:单链表的拆分
    C语言实验——分割整数
    大一上学期
  • 原文地址:https://www.cnblogs.com/TendToBigData/p/10501399.html
Copyright © 2011-2022 走看看