elasticsearch client java 简单code 应用

来源:互联网 发布:cdn网络 多线程 编辑:程序博客网 时间:2024/04/24 08:36
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-applicationSettings  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();}}

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


0 0
原创粉丝点击