I am using Elasticsearch version number 6.2.4.
This is the Configuration file that I am using for java
import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
import java.net.InetAddress;
import java.net.UnknownHostException;
@Configuration
@EnableElasticsearchRepositories
public class Config {
@Bean
public Client elasticsearchClient() throws UnknownHostException {
Settings settings = Settings.builder().put("cluster.name", "elasticsearch").build();
TransportClient client = new PreBuiltTransportClient(settings);
client.addTransportAddress(new TransportAddress(InetAddress.getByName("127.0.0.1"), 9300));
return client;
}
@Bean(name = {"elasticsearchOperations", "elasticsearchTemplate"})
public ElasticsearchTemplate elasticsearchTemplate() throws UnknownHostException {
return new ElasticsearchTemplate(elasticsearchClient());
}
}
Trying to add data to the elasticsearch repository using POST Mapping, I am getting the following error:
{
"timestamp": "2020-04-17T06:46:13.929+0000",
"status": 500,
"error": "Internal Server Error",
"message": "None of the configured nodes are available: [{#transport#-1}
{HUYVYb8YTXSNaYF_Givu5Q}{127.0.0.1}{127.0.0.1:9300}]",
"path": "/event/save"
}
The elasticsearch instance provided by me is not running locally, but on a server provided by the company. The possible source of error that I think is that the Transport Client is not running on port 9300 but on some other port so I need to change its configuration file.
Is there any way that I can find out the transport client address or there is any other error.