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

**URL:** <https://discuss.elastic.co/t/java-lang-nosuchfielderror-connecttimeout-when-trying-to-connect-to-elasticsearch/73706>\
**Category:** Elasticsearch\
**Created:** [February 2, 2017, 3:07pm UTC](https://discuss.elastic.co/t/java-lang-nosuchfielderror-connecttimeout-when-trying-to-connect-to-elasticsearch/73706 "2017-02-02T15:07:49Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marcel](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@Marcel](https://discuss.elastic.co/u/Marcel)\
**Post date:** [February 2, 2017, 3:07pm UTC](https://discuss.elastic.co/t/java-lang-nosuchfielderror-connecttimeout-when-trying-to-connect-to-elasticsearch/73706/1 "2017-02-02T15:07:49Z")

</div>

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

> /\*
> 
> - This build file was generated by the Gradle 'init' task.
> - 
> - This generated file contains a sample Java project to get you started.
> - For more details take a look at the Java Quickstart chapter in the Gradle
> - user guide available at [Java Quickstart - Gradle User Guide Version 3.3](https://docs.gradle.org/3.3/userguide/tutorial_java_projects.html)  
> \*/

> // 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](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](https://mvnrepository.com/artifact/org.elasticsearch/elasticsearch)  
> compile 'org.elasticsearch:elasticsearch:5.2.0'
> 
> // [https://mvnrepository.com/artifact/org.elasticsearch.client/transport](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](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](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](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](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

---

<div class="post-metadata">

**Author:** ![spacy](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@spacy](https://discuss.elastic.co/u/spacy)\
**Post date:** [February 3, 2017, 9:16am UTC](https://discuss.elastic.co/t/java-lang-nosuchfielderror-connecttimeout-when-trying-to-connect-to-elasticsearch/73706/2 "2017-02-03T09:16:47Z")

</div>

> [@Marcel](#):
>
> 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

same here! 😰  
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](https://www.elastic.co/guide/en/x-pack/current/installing-xpack.html))

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

---

<div class="post-metadata">

**Author:** ![Marcel](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@Marcel](https://discuss.elastic.co/u/Marcel)\
**Post date:** [February 3, 2017, 3:34pm UTC](https://discuss.elastic.co/t/java-lang-nosuchfielderror-connecttimeout-when-trying-to-connect-to-elasticsearch/73706/3 "2017-02-03T15:34:19Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![deejay](https://avatars.discourse-cdn.com/v4/letter/d/48db29/32.png) [@deejay](https://discuss.elastic.co/u/deejay)\
**Post date:** [February 6, 2017, 11:55am UTC](https://discuss.elastic.co/t/java-lang-nosuchfielderror-connecttimeout-when-trying-to-connect-to-elasticsearch/73706/4 "2017-02-06T11:55:23Z")

</div>

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%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](http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22org.elasticsearch.client%22%20AND%20a%3A%22transport%22)

---

<div class="post-metadata">

**Author:** ![Marcel](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@Marcel](https://discuss.elastic.co/u/Marcel)\
**Post date:** [February 6, 2017, 3:21pm UTC](https://discuss.elastic.co/t/java-lang-nosuchfielderror-connecttimeout-when-trying-to-connect-to-elasticsearch/73706/5 "2017-02-06T15:21:12Z")

</div>

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](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"}}

---

<div class="post-metadata">

**Author:** ![Marcel](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@Marcel](https://discuss.elastic.co/u/Marcel)\
**Post date:** [February 13, 2017, 6:42am UTC](https://discuss.elastic.co/t/java-lang-nosuchfielderror-connecttimeout-when-trying-to-connect-to-elasticsearch/73706/6 "2017-02-13T06:42:50Z")

</div>

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](http://cluster.name): elasticsearch  
transport.tcp.port: 9300  
[node.name](http://node.name): 127.0.0.1  
network.host: 127.0.0.1

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 13, 2017, 7:01am UTC](https://discuss.elastic.co/t/java-lang-nosuchfielderror-connecttimeout-when-trying-to-connect-to-elasticsearch/73706/7 "2017-02-13T07:01:55Z")

</div>

May be share a sample project on GitHub?

---

<div class="post-metadata">

**Author:** ![Marcel](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@Marcel](https://discuss.elastic.co/u/Marcel)\
**Post date:** [February 17, 2017, 11:51am UTC](https://discuss.elastic.co/t/java-lang-nosuchfielderror-connecttimeout-when-trying-to-connect-to-elasticsearch/73706/8 "2017-02-17T11:51:29Z")

</div>

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

[https://github.com/MarcelMorisse/ResilienceSeismograph](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 🙂

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 17, 2017, 11:52am UTC](https://discuss.elastic.co/t/java-lang-nosuchfielderror-connecttimeout-when-trying-to-connect-to-elasticsearch/73706/9 "2017-03-17T11:52:07Z")

</div>

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