zoukankan      html  css  js  c++  java
  • elasticsearch 5.0 获取 TransportClient 操作客户端java API

    本文转载自:http://blog.csdn.net/likui1314159/article/details/53233881

    elasticsearch 5.0 获取 TransportClient 操作客户端java API 跟之前的版本有点差别了,我也是找了好一会才找到,用到的拿走

    private static TransportClient  transPort = null;   
        private String esClusterName;//集群名
        private String esServerIps;//集群服务IP集合
        private Integer esServerPort;//ES集群端口
    
    
     /**
         *  ES TransPortClient 客户端连接<br>
         *  在elasticsearch平台中,可以执行创建索引,获取索引,删除索引,搜索索引等操作
         * @return
         */
        public TransportClient getTransPortClient() {
            try {
                if (transPort == null) {
    
                    if(esServerIps == null || "".equals(esServerIps.trim())){
                        return  null;
                    }
    
                    Settings settings = Settings.builder()
    //                      .put("cluster.name", esClusterName)// 集群名
                            .put("client.transport.sniff", true)
                            // 自动把集群下的机器添加到列表中
    
                            .build();
                    transPort  = new  PreBuiltTransportClient(settings);
                    String esIps[] = esServerIps.split(",");
                    for (String esIp : esIps) {//添加集群IP列表
                        TransportAddress transportAddress =  new InetSocketTransportAddress(InetAddresses.forString(esIp),9300);
                        transPort.addTransportAddresses(transportAddress);
                    }
                    return transPort;
                } else {
                    return transPort;
                }
            } catch (Exception e) {
                e.printStackTrace();
                if (transPort != null) {
                    transPort.close();
                }
                return null;
            }
        }

    官网参考链接:https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/transport-client.html

  • 相关阅读:
    mysql基础以优化
    Mysql建立索引基础
    Mysql(1)
    SVN学习总结
    Github
    Java Eclipse断点调试
    Java设计模式图文详解
    代理模式
    Java——动态代理技术
    Spring基本概念理解
  • 原文地址:https://www.cnblogs.com/wpcnblog/p/7903708.html
Copyright © 2011-2022 走看看