Transport Client not getting connected 5.6.3 Java API

Continuing the discussion from NoNodeAvailableException, cannot connect Java API and Elasticsearch:

Hi,
I am new to elasticsearch and I wanted to use the Java APIs in Scala to communicate with my ES cluster (one node).
This is my code right now:

var client:TransportClient = null

  def createConnection(addresses:java.util.List[String]):Unit = {

      try {

         client = new PreBuiltTransportClient(Settings.EMPTY)

              .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(XX.XXX.X.XXX), 9300));

         val nodes = client.connectedNodes()

         if (nodes.toList.isEmpty) {

             logger.info("No NODES Connected")

         }

         nodes.toList.foreach { x =>

           logger.info("NODE : " + x)

         }

      } catch {

        case t: Throwable =>

          logger.error("failed to add transport address, got exception: "

            + t.getStackTrace.mkString(" "))

          System.exit(1)

      }

I am running Elasticsearch docker with the following command :

docker run -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e "transport.host=0.0.0.0" -e "cluster.name=elasticsearch" -e "network.host=0.0.0.0" docker.elastic.co/elasticsearch/elasticsearch:5.6.3

I am getting connected nodes as an empty list. When I try to run the execute command I get NoNodesAvailableException.

Could you please tell me what the problem could be?

Thanks in advance :slight_smile:

Is the node running? Can you connect it over the REST layer ? (9200)

What are the logs?

BTW there is now the REST Client which I encourage you to use.

Yes I can connect to it.
I get the following response after curl command:

1513146527 06:28:47 elasticsearch yellow 1 1 5 5 0 0 5 0 - 50.0%

These are the logs of the node :

[2017-12-13T05:46:23,255][INFO ][o.e.n.Node               ] [] initializing ...
[2017-12-13T05:46:23,454][INFO ][o.e.e.NodeEnvironment    ] [jz6H1L5] using [1] data paths, mounts [[/ (overlay)]], net usable_space [250.4gb], net total_space [307.7gb], spins? [possibly], types [overlay]
[2017-12-13T05:46:23,454][INFO ][o.e.e.NodeEnvironment    ] [jz6H1L5] heap size [1.9gb], compressed ordinary object pointers [true]
[2017-12-13T05:46:23,457][INFO ][o.e.n.Node               ] node name [jz6H1L5] derived from node ID [jz6H1L5HThSTM3E0uWYDWg]; set [node.name] to override
[2017-12-13T05:46:23,458][INFO ][o.e.n.Node               ] version[5.6.3], pid[1], build[1a2f265/2017-10-06T20:33:39.012Z], OS[Linux/4.9.24-coreos/amd64], JVM[Oracle Corporation/OpenJDK 64-Bit Server VM/1.8.0_141/25.141-b16]
[2017-12-13T05:46:23,458][INFO ][o.e.n.Node               ] JVM arguments [-Xms2g, -Xmx2g, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -XX:+AlwaysPreTouch, -Xss1m, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djna.nosys=true, -Djdk.io.permissionsUseCanonicalPath=true, -Dio.netty.noUnsafe=true, -Dio.netty.noKeySetOptimization=true, -Dio.netty.recycler.maxCapacityPerThread=0, -Dlog4j.shutdownHookEnabled=false, -Dlog4j2.disable.jmx=true, -Dlog4j.skipJansi=true, -XX:+HeapDumpOnOutOfMemoryError, -Des.cgroups.hierarchy.override=/, -Des.path.home=/usr/share/elasticsearch]
[2017-12-13T05:46:26,040][INFO ][o.e.p.PluginsService     ] [jz6H1L5] loaded module [aggs-matrix-stats]
[2017-12-13T05:46:26,041][INFO ][o.e.p.PluginsService     ] [jz6H1L5] loaded module [ingest-common]
[2017-12-13T05:46:26,041][INFO ][o.e.p.PluginsService     ] [jz6H1L5] loaded module [lang-expression]
[2017-12-13T05:46:26,041][INFO ][o.e.p.PluginsService     ] [jz6H1L5] loaded module [lang-groovy]
[2017-12-13T05:46:26,042][INFO ][o.e.p.PluginsService     ] [jz6H1L5] loaded module [lang-mustache]
[2017-12-13T05:46:26,042][INFO ][o.e.p.PluginsService     ] [jz6H1L5] loaded module [lang-painless]
[2017-12-13T05:46:26,042][INFO ][o.e.p.PluginsService     ] [jz6H1L5] loaded module [parent-join]
[2017-12-13T05:46:26,042][INFO ][o.e.p.PluginsService     ] [jz6H1L5] loaded module [percolator]
[2017-12-13T05:46:26,043][INFO ][o.e.p.PluginsService     ] [jz6H1L5] loaded module [reindex]
[2017-12-13T05:46:26,043][INFO ][o.e.p.PluginsService     ] [jz6H1L5] loaded module [transport-netty3]
[2017-12-13T05:46:26,043][INFO ][o.e.p.PluginsService     ] [jz6H1L5] loaded module [transport-netty4]
[2017-12-13T05:46:26,044][INFO ][o.e.p.PluginsService     ] [jz6H1L5] loaded plugin [ingest-geoip]
[2017-12-13T05:46:26,044][INFO ][o.e.p.PluginsService     ] [jz6H1L5] loaded plugin [ingest-user-agent]
[2017-12-13T05:46:26,044][INFO ][o.e.p.PluginsService     ] [jz6H1L5] loaded plugin [x-pack]
[2017-12-13T05:46:30,581][INFO ][o.e.x.m.j.p.l.CppLogMessageHandler] [controller/67] [Main.cc@128] controller (64 bit): Version 5.6.3 (Build 5bf431d29b5bff) Copyright (c) 2017 Elasticsearch BV
[2017-12-13T05:46:30,650][INFO ][o.e.d.DiscoveryModule    ] [jz6H1L5] using discovery type [single-node]
[2017-12-13T05:46:32,170][INFO ][o.e.n.Node               ] initialized
[2017-12-13T05:46:32,170][INFO ][o.e.n.Node               ] [jz6H1L5] starting ...
[2017-12-13T05:46:32,537][INFO ][o.e.t.TransportService   ] [jz6H1L5] publish_address {10.2.92.83:9300}, bound_addresses {[::]:9300}
[2017-12-13T05:46:32,555][WARN ][o.e.b.BootstrapChecks    ] [jz6H1L5] max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[2017-12-13T05:46:32,589][INFO ][o.e.c.s.ClusterService   ] [jz6H1L5] new_master {jz6H1L5}{jz6H1L5HThSTM3E0uWYDWg}{uS57nWWASUOgBZAojiUHCQ}{10.2.92.83}{10.2.92.83:9300}{ml.max_open_jobs=10, ml.enabled=true}, reason: single-node-start-initial-join[{jz6H1L5}{jz6H1L5HThSTM3E0uWYDWg}{uS57nWWASUOgBZAojiUHCQ}{10.2.92.83}{10.2.92.83:9300}{ml.max_open_jobs=10, ml.enabled=true}]
[2017-12-13T05:46:32,666][INFO ][o.e.x.s.t.n.SecurityNetty4HttpServerTransport] [jz6H1L5] publish_address {10.2.92.83:9200}, bound_addresses {[::]:9200}
[2017-12-13T05:46:32,667][INFO ][o.e.n.Node               ] [jz6H1L5] started
[2017-12-13T05:46:33,024][INFO ][o.e.g.GatewayService     ] [jz6H1L5] recovered [0] indices into cluster_state
[2017-12-13T05:46:33,541][INFO ][o.e.x.m.MachineLearningTemplateRegistry] [jz6H1L5] successfully created .ml-meta index template
[2017-12-13T05:46:33,670][INFO ][o.e.x.m.MachineLearningTemplateRegistry] [jz6H1L5] successfully created .ml-notifications index template
[2017-12-13T05:46:33,734][INFO ][o.e.x.m.MachineLearningTemplateRegistry] [jz6H1L5] successfully created .ml-state index template
[2017-12-13T05:46:33,841][INFO ][o.e.x.m.MachineLearningTemplateRegistry] [jz6H1L5] successfully created .ml-anomalies- index template
[2017-12-13T05:46:34,371][INFO ][o.e.l.LicenseService     ] [jz6H1L5] license [857c851e-fb41-4880-ba28-6241bab0d2a2] mode [trial] - valid
[2017-12-13T05:46:42,636][INFO ][o.e.c.m.MetaDataCreateIndexService] [jz6H1L5] [.monitoring-es-6-2017.12.13] creating index, cause [auto(bulk api)], templates [.monitoring-es], shards [1]/[1], mappings [doc]
[2017-12-13T05:46:42,891][INFO ][o.e.c.m.MetaDataCreateIndexService] [jz6H1L5] [.watches] creating index, cause [auto(bulk api)], templates [watches], shards [1]/[1], mappings [watch]
[2017-12-13T05:46:43,586][INFO ][o.e.c.m.MetaDataMappingService] [jz6H1L5] [.watches/6Rd8EeMVT2qmRn92NWWJdg] update_mapping [watch]
[2017-12-13T05:46:46,261][INFO ][o.e.m.j.JvmGcMonitorService] [jz6H1L5] [gc][14] overhead, spent [273ms] collecting in the last [1s]
[2017-12-13T05:47:44,486][INFO ][o.e.c.m.MetaDataCreateIndexService] [jz6H1L5] [.triggered_watches] creating index, cause [auto(bulk api)], templates [triggered_watches], shards [1]/[1], mappings [triggered_watch]
[2017-12-13T05:47:45,335][INFO ][o.e.c.m.MetaDataCreateIndexService] [jz6H1L5] [.watcher-history-6-2017.12.13] creating index, cause [auto(bulk api)], templates [.watch-history-6], shards [1]/[1], mappings [doc]
[2017-12-13T05:47:45,498][INFO ][o.e.c.m.MetaDataCreateIndexService] [jz6H1L5] [.monitoring-alerts-6] creating index, cause [auto(bulk api)], templates [.monitoring-alerts], shards [1]/[1], mappings [doc]
[2017-12-13T05:47:45,876][INFO ][o.e.c.m.MetaDataMappingService] [jz6H1L5] [.watcher-history-6-2017.12.13/TrJTCOZmSraVbrvWpe6e1Q] update_mapping [doc]
[2017-12-13T05:47:46,019][INFO ][o.e.c.m.MetaDataMappingService] [jz6H1L5] [.watcher-history-6-2017.12.13/TrJTCOZmSraVbrvWpe6e1Q] update_mapping [doc]

Okay. I will try this with the REST Client then.

It sounds like x-pack is running.

Which might indicate that you need to pass a login/password as it is probably secured, no?

When you used the REST endpoint, did you pass some credentials?

Yes I did.
I gave the following curl command: curl http://XX.XXX.X.XXX:9200/_cat/health --user elastic:changeme

Do I need to provide this while adding transport address?

Of course yes. Otherwise security is useless if you can simply join a "secured" cluster without any auth! :stuck_out_tongue:

If you want to use the REST Client, read https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/_basic_authentication.html
With Transport, you need to read https://www.elastic.co/guide/en/x-pack/current/java-clients.html

Oh okay, thanks a lot for the help :slight_smile:

Works fine after I set xpack.security.enabled=false while running the docker.

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