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

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


  • 相关阅读:
    docker 方式安装gitlab时,项目的clone地址及项目文件列表地址为机器名的问题解决办法
    CPU流水线
    Element中el-form嵌套el-table双击编辑提交检验
    java基础知识
    C#多线程下载
    mysql优化
    C++ 算法(一)
    前端vue 的面试总结 以及答案以及前端技术点面试
    C# 组合任务
    C# List去重DistinctBy扩展
  • 原文地址:https://www.cnblogs.com/TendToBigData/p/10501399.html
Copyright © 2011-2022 走看看