Node class, Client interface and RestHighLevelClient

import org.elasticsearch.node.Node;
import org.elasticsearch.client.Client;

Settings settings = Settings.builder().loadFromPath(Paths.get("config/elasticsearch.yml").toAbsolutePath()).build();
Path path = Paths.get("config/elasticsearch.yml").toAbsolutePath();
Environment environment = new Environment(settings, path);
Node nodeTmp = new Node(environment);
clientTmp = nodeTmp.client();

How do I gracefully replace this with the new RestHighLevelClient class?
Is there a way to convert RestHighLevelClient into a Client object to store it in Map<String, Client> instance?

Please format your code, logs or configuration files using </> icon as explained in this guide and not the citation button. It will make your post more readable.

Or use markdown style like:

```
CODE
```

This is the icon to use if you are not using markdown format:

There's a live preview panel for exactly this reasons.

Lots of people read these forums, and many of them will simply skip over a post that is difficult to read, because it's just too large an investment of their time to try and follow a wall of badly formatted text.
If your goal is to get an answer to your questions, it's in your interest to make it as easy to read and understand as possible.

Have a look at Initialization | Java REST Client [7.17] | Elastic

Why would you do this? It's threadsafe so you need only one instance I believe.

This is because the application had a few types of Client for different purposes. For example, TransportClient (implements Client interface), and Client interface provided by Node.client() method. They are stored in a Map<String, Client> object.

It seems like RestHighLevelClient is not meant to be related to other old Client classes and interfaces at all.
Does it sound smarter to use RestHighLevelClient for all connections from 7.8 onward?

Yes. That's the way to go.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.