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("host"), 9300));
The initialization of a
RestHighLevelClient is different. It first requires the initialization
of a low-level client:
RestClient lowLevelRestClient = RestClient.builder( new HttpHost("host", 9200, "http")).build();
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
Which is then passed to the constructor of the
RestHighLevelClient client = new RestHighLevelClient(lowLevelRestClient);
RestHighLevelClient are thread safe. They are
typically instantiated by the application at startup time or when the
first request is executed.
RestHighLevelClient is initialized, it can then be used to
execute any of the supported APIs.
As with the
RestClient must be closed when it
is not needed anymore or when the application is stopped.
So the code that closes the
Must be replaced with: