Do we have to create a Client object for each operation or use the only object for all the operations during the lifecycle of application?
1 Answer
You can instantiate a TransportClient like explained in the documentation :
TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("host1"), 9300))
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("host2"), 9300));
This client instance inherit all methods from the 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
So to answer your question; you can reuse the same client object multiple times.