TransportClient is typically initialized as follows:
Settings settings = Settings.builder() .put("cluster.name", "prod").build(); TransportClient transportClient = new PreBuiltTransportClient(settings) .addTransportAddress(new TransportAddress(InetAddress.getByName("localhost"), 9300)) .addTransportAddress(new TransportAddress(InetAddress.getByName("localhost"), 9301));
The initialization of a
RestHighLevelClient is different. It requires to provide
a low-level client builder as a constructor
RestHighLevelClient client = new RestHighLevelClient( RestClient.builder( new HttpHost("localhost", 9200, "http"), new HttpHost("localhost", 9201, "http")));
RestClient uses Elasticsearch’s HTTP service which is
bounded by default on
9200. This port is different from the port
used to connect to Elasticsearch with a
RestHighLevelClient is thread-safe. It is typically instantiated by the
application at startup time or when the first request is executed.
RestHighLevelClient is initialized, it can be used to execute any
of the supported APIs.
As with the
RestHighLevelClient must be closed when it
is not needed anymore or when the application is stopped.
The code that closes the
must be replaced with: