弹性搜索TransportClient [英] Elastic Search TransportClient
本文介绍了弹性搜索TransportClient的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 ElasticSearch
Java客户端查询弹性搜索。每当我打电话时,我正在初始化运输客户端。这是正确的方式还是应该在应用程序开始时初始化一次,并在关闭时关闭它。
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()));
推荐答案
弹性搜索Java客户端是多线程的,每个新的实例都一个很大的开销。
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.
最好的问候
这篇关于弹性搜索TransportClient的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文