Converting Node Client to Transport client?

I am facing an issue while converting the node client to transport client , can any one please guide me on the conversion , It is saying none of the configured nodes available.

Do any one has any snippet to create a transport client , i am doing with the embedded elastic search server start up in junit test case to connect via transport client , please post any thoughts or ideas to create an embedded es server and connect through transport client .

Thanks,

1 Like

Starting Elasticsearch embedded is not supported.

You should start an external node then run your tests against it.

My 2 cents

Hi David , starting up the custom embedded es cluster and shutting down once after all the unit test are done. And he was using the node client during that time and we decided to go with the transport client and there is the actual issue.

Here is the custom class where we have written to start up embedded one :

  public EmbeddedElasticsearchServer(String clusterName) {
        this.clusterName = clusterName;
        this.dataDirectory = DEFAULT_DATA_DIRECTORY + this.clusterName;
        LOGGER.info("######### Starting embedded elastic search cluster, name = {} in directory = {}", clusterName, this.dataDirectory);
        /* Clean directory before starting server */
        File dataDirectory = new File(this.dataDirectory);
        if (dataDirectory.exists()) {
            EmbeddedElasticsearchServer.deleteDataDirectory(this.dataDirectory);
        }
        this.elasticsearchSettings = ImmutableSettings.settingsBuilder()
                .put("http.enabled", "false")
                .put("path.data", this.dataDirectory)
                .put("index.number_of_replicas", 0)
                .build();
        node = createLocalNode();
        client = this.node.client();
        esClients = new ArrayList<>();
        esClients.add(client);
    }

    public Node createLocalNode() {
        return nodeBuilder()
                .local(true)
                .settings(this.elasticsearchSettings)
                .clusterName(this.clusterName)
                .node();
    }

    public static void deleteDataDirectory(String directory) {
        LOGGER.info("Deleting directory = {}", directory);
        try {
            FileUtils.forceDelete(new File(directory));
        } catch (IOException e) {
            LOGGER.error("Unable to delete directory = {} due to exception = {}", directory, ExceptionUtils.getStackTrace(e));
        }
    }

    @Override
    public Client getClient() {
        return client;
    }

    @Override
    public ArrayList<Client> getEsClients() {
        return esClients;
    }

    @Override
    public void shutDown() {
        String nodeName = node.settings().get("name");
        LOGGER.info("######### Stopping embedded elastic search client and node = " + nodeName);
        this.getEsClients().forEach(client -> client.close());
        node.close();
        LOGGER.info("######### Stopped embedded elastic search node = " + nodeName + ", is closed = " + node.isClosed());
        EmbeddedElasticsearchServer.deleteDataDirectory(this.dataDirectory);
    }

and that was the place where i was trying to inject esclient as transport client instead of node client and i ended up with the none of the configured nodes exception.

thank you for your help...

Please format your code using </> icon as explained in this guide. It will make your post more readable.

Or use markdown style like:

```
CODE
```

I edited your post.

As I said, running elasticsearch embedded is not supported.

When testing, I'm using elasticsearch-maven-plugin and I'm just creating a TransportClient from my tests:

Something like:

    @BeforeClass
    public static void testElasticsearchIsRunning() {
        try {
            client = new PreBuiltTransportClient(Settings.builder().put("client.transport.ignore_cluster_name", true).build())
                    .addTransportAddress(new InetSocketTransportAddress(new InetSocketAddress("127.0.0.1", 9300)));
            client.admin().cluster().prepareHealth().setTimeout(TimeValue.timeValueMillis(200)).get();
        } catch (Exception e) {
            assumeNoException(e);
        }
    }

    @AfterClass
    public static void stopClient() {
        if (client != null) {
            client.close();
            client = null;
        }
    }

Thank you for the suggestion but my issue is different where i am using es version of 1.3 and there is no prebuilt transport client for es version of 1.3 and i didnt get your statement that there is no embedded support or embedded es setup available , if that is the case we are doing by ourself by setting up node and cluster and reaching out via node client , the same embedded cluster i want to use but i have to get with the transport client instead of node client which i have written the above code. Please let me know if i am missing something here ..i really appreciate the help from the community. I mean i am requesting that the proper conversion technique of moving away from node client to transport client with the es version of 1.3.

You really need to upgrade.

1.7 is not supported anymore.
2.4 is going to enter the EOL period soon as 6.0 GA will be released.

Anyway here is the doc for your version : https://www.elastic.co/guide/en/elasticsearch/client/java-api/1.3/transport-client.html

thank you ...but do you see any issue in connecting the created node through transport client instead of node client ? i mean i am able to do the same setup and successful operations with the node client and not able to do with the transport client..i have followed the documentation and provided all the settings needed but still it says none of the configured nodes exception. is there any way which can create a local node with the node builder and access through transport client ?

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