12

I have an application built using the Jhipter generator, which is based on Spring Boot. The latest version of Jhipster allows you to include Elasticsearch as an option, so I have an application which runs an embedded instance of Elasticsearch in development mode and connects to a server instance in production mode.

When the application is running in development mode it connects perfectly fine to the embedded instance, but if I try to connect to an external instance I get the following error on console:

ERROR 7804 --- [ restartedMain] .d.e.r.s.AbstractElasticsearchRepository : failed to load elasticsearch nodes : org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: [{#transport#-1}{127.0.0.1}{127.0.0.1:9300}]

My application is using Spring boot version 1.4.0.RELEASE and according to the elasticsearch.yml, the application has elasticsearch 2.3.5

My application-prod.yml settings:

spring:
 data:
 elasticsearch:
 cluster-name: 
 cluster-nodes: localhost:9300

The default ElasticSearchConfiguration was:

@Configuration
public class ElasticSearchConfiguration {
 @Bean
 public ElasticsearchTemplate elasticsearchTemplate(Client client, Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder) {
 return new ElasticsearchTemplate(client, new CustomEntityMapper(jackson2ObjectMapperBuilder.createXmlMapper(false).build()));
 } 
}

Which I override with:

@Configuration
public class ElasticSearchConfiguration {
 @Value("${spring.data.elasticsearch.cluster-name}")
 private String clusterName;
 @Value("${spring.data.elasticsearch.cluster-nodes}")
 private String clusterNodes;
 @Bean
 public ElasticsearchTemplate elasticsearchTemplate() throws UnknownHostException {
 String server = clusterNodes.split(":")[0];
 Integer port = Integer.parseInt(clusterNodes.split(":")[1]);
 Settings settings = Settings.settingsBuilder()
 .put("cluster.name", clusterName).build();
 client = TransportClient.builder().settings(settings).build()
 .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(server), port));
 return new ElasticsearchTemplate(client);
 }
 }

But I am still not able to connect elasticsearch using prod yml.

While debugging I got the following error while ElasticsearchTemplate bean creation:

Method threw 'java.lang.StackOverflowError' exception. Cannot evaluate org.elasticsearch.common.inject.InjectorImpl.toString()

How can I resolve this issue?

asked Dec 26, 2016 at 13:15
5
  • is there any solution for this? i am trying to connect to the remote. Please update with the answer Commented May 3, 2017 at 11:51
  • 1
    Did you ran the elastic search on remote? When using remote elasticsearch you can keep using the default ElasticSearchConfiguration. Just run elasticsearch on remote. Commented May 4, 2017 at 12:12
  • I am running my elasticsearch in aws instance and ports opened accordingly. unable to connect from another aws instance where my app is running. here is my issue github.com/jhipster/generator-jhipster/issues/…. Need help this. Commented May 4, 2017 at 12:39
  • I have this issue today and when I downgrade ES from 2.4 to 1.7.3, the connection established Commented Jun 28, 2017 at 23:25
  • I'm confused, is your production cluster's master node running on localhost? The No nodes available message is trying to connect locally. Commented Dec 27, 2018 at 22:05

1 Answer 1

2

I've a working Jhipster project with Elasticsearch. If your Elastic instance is running locally on default ports, you can leave those properties empty. It's not needed to change the class ElasticSearchConfiguration

Using in Production

In production, JHipster expects an external Elasticsearch instance. By default, the application looks for an Elasticsearch instance running on localhost. This can be configured by using the standard Spring Boot properties, in the application-prod.yml file.

answered May 3, 2019 at 21:51
Sign up to request clarification or add additional context in comments.

1 Comment

Can you please elaborate it more briefly?

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.