ElasticSearch Java API:客户端创建
ElasticSearch Java API: Client creation
我们是否必须为每个操作创建一个 Client 对象,或者在应用程序的生命周期中为所有操作使用唯一的对象?
您可以像 documentation 中解释的那样实例化一个 TransportClient :
TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("host1"), 9300))
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("host2"), 9300));
此客户端实例继承了 AbstractClient 的所有方法:
admin, bulk, bulk, clearScroll, clearScroll, count, count, delete,
delete, deleteIndexedScript, deleteIndexedScript, execute, execute, exists,
exists, explain, explain, fieldStats, fieldStats, get, get,
getIndexedScript, getIndexedScript, headers, index, index, multiGet, multiGet, multiPercolate, multiPercolate, multiSearch, multiSearch,
multiTermVectors, multiTermVectors, percolate, percolate, prepareBulk,
prepareClearScroll, prepareCount, prepareDelete, prepareDelete,
prepareDeleteIndexedScript, prepareDeleteIndexedScript, prepareExecute,
prepareExists, prepareExplain, prepareFieldStats, prepareGet,
prepareGet, prepareGetIndexedScript, prepareGetIndexedScript,
prepareIndex, prepareIndex, prepareIndex, prepareMultiGet,
prepareMultiPercolate, prepareMultiSearch, prepareMultiTermVectors,
preparePercolate, preparePutIndexedScript, preparePutIndexedScript,
prepareSearch, prepareSearchScroll, prepareSuggest, prepareTermVector,
prepareTermVector, prepareTermVectors, prepareTermVectors,
prepareUpdate, prepareUpdate, putIndexedScript, putIndexedScript,
search, search, searchScroll, searchScroll, settings, suggest, suggest,
termVector, termVector, termVectors, termVectors, threadPool, update,
update
所以回答你的问题;您可以多次重复使用同一个客户端对象。
我们是否必须为每个操作创建一个 Client 对象,或者在应用程序的生命周期中为所有操作使用唯一的对象?
您可以像 documentation 中解释的那样实例化一个 TransportClient :
TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("host1"), 9300))
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("host2"), 9300));
此客户端实例继承了 AbstractClient 的所有方法:
admin, bulk, bulk, clearScroll, clearScroll, count, count, delete,
delete, deleteIndexedScript, deleteIndexedScript, execute, execute, exists,
exists, explain, explain, fieldStats, fieldStats, get, get,
getIndexedScript, getIndexedScript, headers, index, index, multiGet, multiGet, multiPercolate, multiPercolate, multiSearch, multiSearch,
multiTermVectors, multiTermVectors, percolate, percolate, prepareBulk,
prepareClearScroll, prepareCount, prepareDelete, prepareDelete,
prepareDeleteIndexedScript, prepareDeleteIndexedScript, prepareExecute,
prepareExists, prepareExplain, prepareFieldStats, prepareGet,
prepareGet, prepareGetIndexedScript, prepareGetIndexedScript,
prepareIndex, prepareIndex, prepareIndex, prepareMultiGet,
prepareMultiPercolate, prepareMultiSearch, prepareMultiTermVectors,
preparePercolate, preparePutIndexedScript, preparePutIndexedScript,
prepareSearch, prepareSearchScroll, prepareSuggest, prepareTermVector,
prepareTermVector, prepareTermVectors, prepareTermVectors,
prepareUpdate, prepareUpdate, putIndexedScript, putIndexedScript,
search, search, searchScroll, searchScroll, settings, suggest, suggest,
termVector, termVector, termVectors, termVectors, threadPool, update,
update
所以回答你的问题;您可以多次重复使用同一个客户端对象。