Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elastic Search TransportClient

I am using ElasticSearch Java client to query elastic search. I am initializing transport client every time I have to make a call. Is this the right way or should I initialize once during the start of the application and close it at shutdown.

Following is the code to initialize client

 Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name", Config.getEsClusterName()).put("client.transport.ignore_cluster_name", true).build();
 Client esClient = new TransportClient(settings).addTransportAddress(new InetSocketTransportAddress(Config.getEsHost(), Config.getEsPort()));
like image 769
usha Avatar asked Jun 03 '14 21:06

usha


2 Answers

The elasticsearch Java client is multithreaded and each new instance has a large overhead.

This should be instantiated once at the start of your program and shared across all callers.

Best Regards

like image 147
ppearcy Avatar answered Nov 11 '22 13:11

ppearcy


I created a github repository for usage of java elasticsearch transport client[with singleton design pattern].. please ..make use of it.refer

like image 21
BlackPOP Avatar answered Nov 11 '22 14:11

BlackPOP