@Override public TransportClient createClient(Map<String, String> clientConfig) { Settings settings = Settings.settingsBuilder().put(clientConfig).build(); TransportClient transportClient = TransportClient.builder().settings(settings).build(); for (TransportAddress address : ElasticsearchUtils.convertInetSocketAddresses(transportAddresses)) { transportClient.addTransportAddress(address); } // verify that we actually are connected to a cluster if (transportClient.connectedNodes().isEmpty()) { // close the transportClient here IOUtils.closeQuietly(transportClient); throw new RuntimeException("Elasticsearch client is not connected to any Elasticsearch nodes!"); } if (LOG.isInfoEnabled()) { LOG.info("Created Elasticsearch TransportClient with connected nodes {}", transportClient.connectedNodes()); } return transportClient; }
/** * create a elasticsearch transport client (remote elasticsearch) * @param addresses an array of host:port addresses * @param clusterName */ public ElasticsearchClient(final String[] addresses, final String clusterName) { // create default settings and add cluster name Settings.Builder settings = Settings.builder() .put("cluster.name", clusterName) .put("cluster.routing.allocation.enable", "all") .put("cluster.routing.allocation.allow_rebalance", "true"); // create a client TransportClient tc = TransportClient.builder() .settings(settings.build()) .build(); for (String address: addresses) { String a = address.trim(); int p = a.indexOf(':'); if (p >= 0) try { InetAddress i = InetAddress.getByName(a.substring(0, p)); int port = Integer.parseInt(a.substring(p + 1)); tc.addTransportAddress(new InetSocketTransportAddress(i, port)); } catch (UnknownHostException e) { DAO.severe(e); } } this.elasticsearchClient = tc; }
TransportClient.Builder builder = TransportClient.builder();
TransportClient tClient = TransportClient.builder().settings(settings).build(); for (String h : nodeList) { String[] nodes = h.split(":");
client = TransportClient.builder().build();
TransportClient client = TransportClient.builder().settings(settings).build();
@Bean public Client client() throws Exception { Settings esSettings = Settings.builder().put("cluster.name", clusterName) .put("client.transport.sniff", true)//增加嗅探机制,找到ES集群 .put("thread_pool.search.size", Integer.parseInt(poolSize))//增加线程池个数,暂时设为5 .build(); return TransportClient.builder() .settings(esSettings) .build() .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(hostName), Integer.parseInt(port))); }
/** * Create a client from the settings * * @param settings the settings used to create the client * @return transport client */ @Override public TransportClient create(Settings settings) { return TransportClient.builder().settings(settings).build(); } }
@Bean public TransportClient client() { TransportClient client = null; try { client = TransportClient.builder().settings(this.settings()).build() // .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(nodeAddr), nodePort)); } catch (UnknownHostException ex) { log.error("init es client host:{},port:{} error", nodeAddr, nodePort, ex); } return client; }
@Override public Client getClient() { Settings settings = Settings.settingsBuilder() .put(clientSettings) .build(); TransportAddress address = new InetSocketTransportAddress(new InetSocketAddress(transportHost, transportPort)); return TransportClient.builder().settings(settings).build().addTransportAddress(address); } }
@Override public TransportClient createClient() { return TransportClient .builder() .settings(Settings.builder().EMPTY_SETTINGS) .build(); }
private Client getClient() throws AppException { final org.elasticsearch.common.settings.Settings settings = org.elasticsearch.common.settings.Settings.settingsBuilder() .put("client.transport.sniff", true) //being able to retrieve other nodes .put("cluster.name", "hops").build(); return TransportClient.builder().settings(settings).build() .addTransportAddress(new InetSocketTransportAddress( new InetSocketAddress(getElasticIpAsString(), this.settings.getElasticPort()))); }
private Client getElasticClient() throws UnknownHostException { if (this.elasticClient == null) { Settings settings = Settings.settingsBuilder() .put("cluster.name", elasticsearchProperties.getElasticsearchClusterName()) .put("client.transport.ping_timeout", elasticsearchProperties.getElasticsearchTransportPingTimeout()) .build(); this.elasticClient = TransportClient.builder() .settings(settings) .build() .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(elasticsearchProperties.getElasticsearchHost()), elasticsearchProperties.getElasticsearchPort())); } return this.elasticClient; }
@Override public Client get() { TransportClient transportClient = TransportClient.builder().build(); ConsumerChainer<Host> consumer = Throwing.consumer(host -> transportClient .addTransportAddress( new InetSocketTransportAddress( InetAddress.getByName(host.getHostName()), host.getPort()))); hosts.forEach(consumer.sneakyThrow()); return transportClient; } }