6

I'm trying to search from Elastic Search within my Java Web Service, here's how I use now :

    Client client = new PreBuiltTransportClient(Settings.EMPTY).addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("192.168.10.150"), 9200));
    SearchResponse searchResponse = client.prepareSearch().execute().actionGet();

The 1st line could work without an error, but when it goes to the 2nd line, the exception down below will occur :

NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{TskPSVeBRR6CvCzP9EVhkQ}{192.168.10.150}{192.168.10.150:9200}]]

No matter I use 9200 or 9300 to set the port, the results are the same.

Also, I've tried to search from my .Net program using NEST, and it run just fine. Here's how I tried :

    var node = new Uri("http://192.168.10.150:9200");
    var settings = new ConnectionSettings(node).DefaultIndex("iod-2017.03.08.*");
    _EsClient = new ElasticClient(settings);
    var index = String.Format("iod-{0}.{1:00}.{2:00}.*", item.TriggerTime.Year, item.TriggerTime.Month, item.TriggerTime.Day);
    var uniqueId = item.UniqueId.ToString();
    var result = _EsClient.Search<logs>(s => s.Index(index).Query(q => q.Match(t => t.Field(l => l.id).Query(uniqueId))));

Did I do anything(Firewall, version of library, method to call the API, etc) wrong with my Java program? My current Java version is 1.8.0.121, the version of Elastic Search and Transport Client are both 5.2. Thanks!

Rahul
  • 15,979
  • 4
  • 42
  • 63
Alanight
  • 353
  • 2
  • 8
  • 23
  • Can you check whether you can telnet to the ES box on port 9300 from your local box ? 9200 seems to be open as it is being used by your .NET client – Rahul Mar 16 '17 at 09:18
  • 1
    Are you using a cluster name other than elasticsearch ? If yes, have you updated the same in settings ? – Rahul Mar 16 '17 at 09:22
  • I've solve my problem! You're right, I should use 9300 port, but the critical error is that I didn't set the cluster name correctly. I can search after I set cluster.name in Settings. Thank you very much! – Alanight Mar 16 '17 at 09:26
  • Glad, it solved your problem. Have added the same in an answer. Please accept it – Rahul Mar 16 '17 at 09:30

7 Answers7

6

As discussed in comments,

If you are using a cluster name other than elasticsearch, then you need to update the same in settings.

Settings settings = Settings.builder()
        .put("cluster.name", "myClusterName").build();
Uyric
  • 646
  • 7
  • 17
Rahul
  • 15,979
  • 4
  • 42
  • 63
2

I was facing the same issue, my cluster name & everything were correct, but my elastic cluster was using X-Pack Security. And it was only because of that.

Here is solutions - https://www.elastic.co/guide/en/x-pack/current/java-clients.html

CR Sardar
  • 921
  • 2
  • 17
  • 32
0

From documentation,

// on startup

TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)
        .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("host1"), 9300))
        .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("host2"), 9300)); 
zondo
  • 19,901
  • 8
  • 44
  • 83
Praveen
  • 25
  • 9
0

If you are install elasticsearch from extracted file (e.g.: elasticsearch-5.4.0.tar.gz), please try to install it in through yum or other RPM tool. https://www.elastic.co/guide/en/elasticsearch/reference/current/rpm.html It help me solve this problem.

0

Before executing the program make sure you ran the elasticSearch.bat batch file present under ElasticSearch -> config folder. Also make sure you see "started" logged in the console where you ran the batch file.

You can check if elastic search started successfully or not by hitting the URL localhost:9200. You should see a page looking something like this:

{
  "name" : ...,
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : ...,
  "version" : {
    "number" : "5.5.2",
    ...
    "build_snapshot" : false,
    "lucene_version" : "6.6.0"
  },
  "tagline" : "You Know, for Search"
}
ivarni
  • 17,658
  • 17
  • 76
  • 92
Mini
  • 1
0

Add the cluster name as a parameter on the connection URI:

  1. Go to http://<elasticsearch_host>:9200
  2. Retrieve the cluster_name value and add it as a parameter to the connection URI: elasticsearch://<elasticsearch_host>:9300?cluster.name=<cluster_name_value>
Joel Mata
  • 456
  • 4
  • 8
0

This Exception is pointing to elasticSearch transport client is not able to establish a connection with elasticsearch server.

Root cause might be the port name or IP/hostname of server OR cluster Name OR Authentication is incorrect.

Open elasticSearch.yaml file and validate all details correctly. To ignore clusterName validation by using the following configuration params.

client.transport.ignore_cluster_name = true

Full code snippet to create transport Client is:

 Settings settingsBuilder = Settings.builder()
            .put("cluster.name", DBPropertyUtil.getPropertyByName("es.cluster")).put("client.transport.sniff", true).put("client.transport.ignore_cluster_name", true).build();
            //.put("client.transport.sniff", true).put("path.home", ".").build();
         Client client = new PreBuiltTransportClient(settingsBuilder)
            .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(host), port));

Specify host and port as per your server. This code is working fine for me.

Saeed Hassanvand
  • 931
  • 1
  • 14
  • 31
Rajeev Rathor
  • 1,830
  • 25
  • 20