java.lang.NoSuchFieldError: connectTimeout when trying to connect to ElasticSearch

Hi there,

I am quite new to use Elasticsearch in my Java project to index Reddit post and I am kindly asking for your help.

I have installed Elasticsearch 5.2.0 together with Kibana and logstash. X-Pack was installed for Elasticsearch 5.2 and Kibana, but I was not able to install X-Pack with logstash (Error: Something went wrong when installing x-pack, message can't dup Nilclass)

I left Elasticsearch mostly untouched only changing the cluster name and added a new user.
Calling localhost:9200 returns

{
"name" : "node-1",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "gC7rZjBcRuu9jm71Kt15AQ",
"version" : {
"number" : "5.2.0",
"build_hash" : "24e05b9",
"build_date" : "2017-01-24T19:52:35.800Z",
"build_snapshot" : false,
"lucene_version" : "6.4.0"
},
"tagline" : "You Know, for Search"
}

When I now would like to connect my Java application with Elasticsearch I get a

Exception in thread "main" java.lang.NoSuchFieldError: connectTimeout
at org.elasticsearch.transport.netty4.Netty4Transport.createBootstrap(Netty4Transport.java:206)
at org.elasticsearch.transport.netty4.Netty4Transport.doStart(Netty4Transport.java:171)
at org.elasticsearch.common.component.AbstractLifecycleComponent.start(AbstractLifecycleComponent.java:69)
at org.elasticsearch.transport.TransportService.doStart(TransportService.java:202)
at org.elasticsearch.common.component.AbstractLifecycleComponent.start(AbstractLifecycleComponent.java:69)
at org.elasticsearch.client.transport.TransportClient.buildTemplate(TransportClient.java:198)
at org.elasticsearch.client.transport.TransportClient.(TransportClient.java:258)
at org.elasticsearch.transport.client.PreBuiltTransportClient.(PreBuiltTransportClient.java:125)
at org.elasticsearch.transport.client.PreBuiltTransportClient.(PreBuiltTransportClient.java:111)
at org.elasticsearch.transport.client.PreBuiltTransportClient.(PreBuiltTransportClient.java:101)
at qualitativeAnalysis.dbi.elasticsearch.AbstractConnector.connect(AbstractConnector.java:86)
at qualitativeAnalysis.textCrawler.reddit.Main.main(Main.java:21)

After several tries I ended with this approach to connect which produces the Exception

public void connect() {
if (isConnected()) {
return;
}

  String username  = "java";
  String password  = "el4s7ic4java";
  
  // Setup client configuration
  Settings settings = Settings.builder()
          .put("cluster.name",                            "elasticsearch")
          //.put("shield.user",                             username+":"+password)
          .put("client.transport.sniff",                  true)
          //.put("client.transport.ping_timeout",           "60s")
          //.put("client.transport.nodes_sampler_interval", "5s")
          .build();
  
  // Create Client instance, with needed plugins and settings
  _client = new PreBuiltTransportClient(Settings.EMPTY);
  //PreBuiltXPackTransportClient(settings);
         // .addPlugins(ShieldPlugin.class)
         // .settings(settings)
         // .build();

  // Add server address
  LOGGER.debug("Connecting on " + _hostname + " ...");
  _client.addTransportAddress(new InetSocketTransportAddress(new InetSocketAddress(_hostname, 9300)));
  setConnected();
  
  LOGGER.debug("Sucessfully connected on " + _hostname);

}

I am using Gradle to manage my Java liberaries, here is my build.gradle

/*

// Apply the java plugin to add support for Java
apply plugin: 'java'
apply plugin: 'eclipse'

// In this section you declare where to find the dependencies of your project
repositories {
// Use jcenter for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
//jcenter()
mavenCentral()

maven {
url "https://maven.elasticsearch.org/releases"

}
}

dependencies {
// The production code uses Guava
compile 'com.google.guava:guava:20.0'

//QualitatitveAnalysis

// https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.7'

// https://mvnrepository.com/artifact/org.elasticsearch/elasticsearch
compile 'org.elasticsearch:elasticsearch:5.2.0'

// https://mvnrepository.com/artifact/org.elasticsearch.client/transport
compile group: 'org.elasticsearch.client', name: 'transport', version: '5.1.2'

// https://mvnrepository.com/artifact/org.elasticsearch.plugin/shield
compile group: 'org.elasticsearch.plugin', name: 'shield', version: '2.4.4'

// https://mvnrepository.com/artifact/com.google.code.gson/gson
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.0'

// https://mvnrepository.com/artifact/org.twitter4j/twitter4j-core
compile group: 'org.twitter4j', name: 'twitter4j-core', version: '4.0.6'

// https://mvnrepository.com/artifact/javax.json/javax.json-api
//compile group: 'javax.json', name: 'javax.json-api', version: '1.0'

//jReddit Jar, compiled from src
compile files('libs/jReddit-1.0.4-SNAPSHOT.jar')

// Use JUnit test framework
testCompile 'junit:junit:4.12'

}

If you would have to guess, I suspect an inconsistency between elasticsearch 5.2.0 with 'org.elasticsearch.client', name: 'transport', version: '5.1.2', but I was not able to find the 5.2.0 version of it.

Can you please help, many thanks in advance
Marcel

1 Like

same here! :cold_sweat:
I left it completely untouched and just followed the instructions until Step 7. (Installing X-Pack | X-Pack for the Elastic Stack [6.2] | Elastic)

Edit:
I tried a local, manual installation of x-pack for Logstash and this gave me success. Maybe it helps you?

Thanks, I will try a manual installation later today. Where do I copy the unzipped x-pack folder?

I have tried today to use Elasticsearch 5.1.2 with Kibana and Logstash (both 5.1.2) to avoid jar inconsistencies (switched to elasticsearch.jar (version 5.1.2) but it produces the same Exception, any suggestions?

I had the same issue. You will need to include/upgrade to the following elasticsearch client and plugin jars:

transport-5.2.0.jar
transport-netty3-client-5.2.0.jar
transport-netty4-client-5.2.0.jar
reindex-client-5.2.0.jar
percolator-client-5.2.0.jar
lang-mustache-client-5.2.0.jar

You can find them here:

http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22org.elasticsearch.plugin%22

http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22org.elasticsearch.client%22%20AND%20a%3A%22transport%22

Thanks a lot, I have updated my build.gradle.

I am now getting a different exception, I think I have overseen a configuration. I also suspect that the username and password have to be set somewhere, but I am not sure where.

Exception in thread "main" NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{B7baZTscSpuexBl8-sTwHg}{127.0.0.1}{127.0.0.1:9300}]]
at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:344)
at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:242)
at org.elasticsearch.client.transport.TransportProxyClient.execute(TransportProxyClient.java:59)
at org.elasticsearch.client.transport.TransportClient.doExecute(TransportClient.java:356)
at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:403)
at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:392)
at org.elasticsearch.client.support.AbstractClient$IndicesAdmin.execute(AbstractClient.java:1220)
at org.elasticsearch.client.support.AbstractClient$IndicesAdmin.exists(AbstractClient.java:1242)
at qualitativeAnalysis.dbi.elasticsearch.AbstractConnector.createIndex(AbstractConnector.java:117)
at qualitativeAnalysis.textCrawler.reddit.Main.main(Main.java:22)

My connection build up in Java looks quite the same

String username = "java";
String password = "el4s7ic4java";

  // Setup client configuration
  Settings settings = Settings.builder()
          .put("cluster.name",                            "elasticsearch")
          //.put("shield.user",                             username+":"+password)
          //.put("client.transport.sniff",                  true)
          //.put("client.transport.ping_timeout",           "60s")
          //.put("client.transport.nodes_sampler_interval", "5s")
          .build();
  
  // Create Client instance, with needed plugins and settings
  _client = new PreBuiltTransportClient(settings);
  //PreBuiltXPackTransportClient(settings);
         // .addPlugins(ShieldPlugin.class)
         // .settings(settings)
         // .build();

  // Add server address
  LOGGER.debug("Connecting on " + _hostname + " ...");
  _client.addTransportAddress(new InetSocketTransportAddress(new InetSocketAddress(_hostname, 9300)));
  setConnected();
  
  LOGGER.debug("Sucessfully connected on " + _hostname);

The _hostname and node.name is set to 127.0.0.1,

Calling http://localhost:9200/_nodes, returns

{"_nodes":{"total":1,"successful":1,"failed":0},"cluster_name":"elasticsearch","nodes":{"Q635TLitSBuJGv5PT1B0JA":{"name":"127.0.0.1","transport_address":"127.0.0.1:9300","host":"127.0.0.1","ip":"127.0.0.1","version":"5.2.0","build_hash":"24e05b9","total_indexing_buffer":211261849,"roles":["master","data","ingest"],"settings":{"client":{"type":"node"},"cluster":{"name":"elasticsearch"},"http":{"type":"security4"},"node":{"name":"127.0.0.1"},"path":{"logs":"C:\elasticsearch-5.2.0\logs","home":"C:\elasticsearch-5.2.0"},"transport":{"tcp":{"port":"9300"},"type":"security4"}}

After reading a bit in the forum, I have tried several approaches but failed. It still seems so that I am not able to connect to the node via the Java API. Do you have an advice for me?

The elasticsearch.yml:

cluster.name: elasticsearch
transport.tcp.port: 9300
node.name: 127.0.0.1
network.host: 127.0.0.1

May be share a sample project on GitHub?

Hi, thanks for will to help. I have uploaded my project to Github, it can be found here

https://github.com/MarcelMorisse/ResilienceSeismograph

Maybe a few words to get a quick overview. The goal of the program is to gather Bitcoin data and analyse it with statistical methods and text mining. I am using elasticsearch to gather post from reddit and analyse it. It can be found in the qualitativeAnalysis folder, the class (AbstractConnector.java) which has implemented the connection is in the dbi/elasticsearch folder. To start crawling data, I call the main method in Main.java in the textCrawler/reddit folder. Maybe a word of warning: As it is an one man project, I postponed commenting my code to after implementation :slight_smile:

The Elasticsearch (5.2 but also 5.1.2 on another maschine) implementation is more or less untouched, I have added a user "java", password = "el4s7ic4java", the elasticsearch.yml looks like this (the bold ones are not used)

======================== Elasticsearch Configuration =========================

cluster.name: elasticsearch
transport.tcp.port: 9300
node.name: 127.0.0.1
'#node.attr.rack: r1
'#path.data: /path/to/data
'#path.logs: /path/to/logs
'#bootstrap.memory_lock: true
network.host: 127.0.0.1
'#http.port: 9200
'#discovery.zen.ping.unicast.hosts: ["host1", "host2"]
'#discovery.zen.minimum_master_nodes: 3
'#gateway.recover_after_nodes: 3
'#action.destructive_requires_name: true

Logstash is running with the following conf:

input { stdin { } }
output {
elasticsearch {
hosts => [ "localhost:9200" ]
user => java
password => el4s7ic4java
}
stdout { codec => rubydebug }
}

Many thanks for any help
Marcel

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