问题
How to configure elasticsearch 5 TransportClient.
Now TransportClient is abstract class. I found only PreBuiltTransportClient, this is the new way to configure elasticsearch Client ?
回答1:
Yes, you can find that in the official documentation for 5.0 as well
Settings settings = Settings.builder()
.put("cluster.name", "ElasticSearchClusterName");
TransportClient client = new PreBuiltTransportClient(settings)
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("host1"), 9300))
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("host2"), 9300));
It is worth nothing that the PreBuiltTransportClient
is pre-configured with the following modules:
- Netty3
- Netty4
- Reindex
- Percolator
- Mustache
Also make sure that you have a dependency on the transport
artifact:
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>5.0.0-beta1</version>
</dependency>
回答2:
First download respective jar file and keep that in lib folder and add them to build path. You can follow below code to configure it:
Settings settings = Settings.builder()
.put("cluster.name", "ElasticSearchClusterName")
//.put("client.transport.sniff", true)
//.put("shield.user", elasticUserName+":"+elasticPassword)
.build();
TransportClient client = new PreBuiltTransportClient(settings)
.addTransportAddress(new InetSocketTransportAddress(elasticHostOne, elasticTransportPort))
.addTransportAddress(new InetSocketTransportAddress(elasticHostTwo, elasticTransportPort))
.addTransportAddress(new InetSocketTransportAddress(elasticHostThree, elasticTransportPort));
来源:https://stackoverflow.com/questions/38883784/how-to-configure-elasticsearch-5