1

I am using Elasticsearch in a Java Project using Maven:

...
 <elasticsearch.version>6.7.0</elasticsearch.version>
...
    <!-- Elasticsearch -->
    <dependency>
        <groupId>org.elasticsearch</groupId>
        <artifactId>elasticsearch</artifactId>
        <version>${elasticsearch.version}</version>
    </dependency>

    <dependency>
        <groupId>org.elasticsearch.client</groupId>
        <artifactId>transport</artifactId>
        <version>${elasticsearch.version}</version>
    </dependency>

    <dependency>
        <groupId>org.elasticsearch.plugin</groupId>
        <artifactId>transport-netty4-client</artifactId>
        <version>${elasticsearch.version}</version>
    </dependency>

    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-to-slf4j</artifactId>
        <version>2.8.2</version>
    </dependency>
    <!-- Elasticsearch -->        

When I try to initialize a TransportClient in order to index a document it gives me the error:

    NoNodeAvailableException[None of the configured nodes are available: 
    [{#transport#-1}{BHMBbfcrSUOM_Pyaf1LcnA}{localhost}{127.0.0.1:9300}]]

Maybe a need to add more information in config/elasticsearch.yaml about transportartion or the current configuration is wrong.

Java code:

    TransportAddress address;
    TransportClient client;
    Settings settings;

    try {
        address = new TransportAddress(InetAddress.getByName("localhost"), 9300);
        settings = Settings
                    .builder()
                    .put("cluster.name", "lib2life")
                    .put("client.transport.sniff", true)
                    .build();

        /* Initiate Transport Client */
        client = new PreBuiltTransportClient(settings)
                    .addTransportAddress(address);

        /* Verify it cluster is healthy */
        ClusterHealthResponse clusterResponse = client
                    .admin()
                    .cluster()
                    .prepareHealth()
                    .setWaitForGreenStatus()
                    .setTimeout(TimeValue.timeValueSeconds(5))
                    .execute() //Error here
                    .actionGet();

         ... (more code)
    }

elasticsearch.yaml:

# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
cluster.name: lib2life
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
#network.host: 192.168.0.1

network.host:localhost
network.transport.tcp.port:9300

#
# Set a custom port for HTTP:
#
#http.port: 9200
#
# For more information, consult the network module documentation.
#

(The other info inside elasticsearch.yaml is commented)

localhost:9200 gives me:

{
  "name" : "IRINAMW7",
  "cluster_name" : "lib2life",
  "cluster_uuid" : "-wL1-xdESnyoknD2ZqALDQ",
  "version" : {
    "number" : "7.1.1",
    "build_flavor" : "default",
    "build_type" : "zip",
    "build_hash" : "7a013de",
    "build_date" : "2019-05-23T14:04:00.380842Z",
    "build_snapshot" : false,
    "lucene_version" : "8.0.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}
WhiteW
  • 181
  • 1
  • 1
  • 11

2 Answers2

2

I solved the problem. The issue was that I was using Elasticsearch 6.7.0 version with TransportClient, which is deprecated and replaced by RestHighLevelClient. Also, I had to use port 9200 and to uncomment http.port: 9200 and discovery.seed_hosts: ["host1", "host2"] from elasticsearch.yaml

WhiteW
  • 181
  • 1
  • 1
  • 11
0

The issue is with your port configuration, you are using port 9300 for REST call which actully used for inter-nodes communication in elasticsearch cluster. please change below java code to use the port 9200.

address = new TransportAddress(InetAddress.getByName("localhost"), 9200);

Please read more about ports of es https://discuss.elastic.co/t/elasticsearch-port-9200-or-9300/72080/2

Amit
  • 30,756
  • 6
  • 57
  • 88
  • Still gives me: NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{QJvbXzFLR8mOzAbajIUI1Q}{localhost}{127.0.0.1:9200}]] – WhiteW Jul 17 '19 at 12:43
  • @WhiteW , are you running both ES and your application on the same system? – Amit Jul 17 '19 at 14:47
  • @WhiteW also why port 9200 is commented in your .yml – Amit Jul 17 '19 at 16:12
  • Yes, I am also using Grizzly server which runs by default on 8080 port. The HTTP 9200 port is commented in elasticsearch.yaml because I thought 9200 and 9300 ports are used for different scopes and I need 9300. – WhiteW Jul 18 '19 at 06:21
  • @WhiteW, this is not how it works, grizzly is an application server which runs on 8080 port, but in your code, you are creating a client to ES server which runs on 9200 and 9300 port, which is used for different use cases mentioned in my answer link, in your use case it requires 9200 port. so you need to uncomment 9200 port and than restart your ES node and test it again. – Amit Jul 18 '19 at 06:25
  • Yes, I understand but there is still something wrong because it is not working with cluster.name: lib2life and http.port: 9200 in elasticsearch.yaml . TransportAdress is: new TransportAddress(InetAddress.getLocalHost(), 9200); – WhiteW Jul 18 '19 at 06:34
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/196618/discussion-between-amit-khandelwal-and-whitew). – Amit Jul 18 '19 at 06:34