2
votes

I'm using ElasticSearch-5.2.1 with springboot and getting below error in elasticsearch.bat

java.lang.IllegalStateException: Received message from unsupported version: [2.0.0] minimal compatible version is: [5.0.0]

and in my application console getting below error:

Caused by: org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: [{#transport#-1}{127.0.0.1}{127.0.0.1:9300}]

When i search in google it is asking to upgrade transport client but How do i upgrade the transport client from 2.0 to 5.0

below is my config code:

@Value("${elasticsearch.port}")
private int EsPort;

@Value("${elasticsearch.clustername}")
private String EsClusterName;

@Value("${elasticsearch.host}") private String EsHost;

 @Bean
public Client client() throws Exception {

    Settings esSettings = Settings.settingsBuilder().put("cluster.name", EsClusterName).build();


    return TransportClient.builder()
            .settings(esSettings)
            .build()
            .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(EsHost), EsPort));
}

@Bean
public ElasticsearchOperations elasticsearchTemplate() throws Exception {
    return new ElasticsearchTemplate(client());
}
1

1 Answers

4
votes

Make sure that elastic cluster is up: hit url http://localhost:9200 in browser. it should give some thing similar to below:

    {
  "name" : "JXfjbaL",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "7XzGYbE8QkGCMRwbqEriJw",
  "version" : {
    "number" : "5.5.3",
    "build_hash" : "9305a5e",
    "build_date" : "2017-09-07T15:56:59.599Z",
    "build_snapshot" : false,
    "lucene_version" : "6.6.0"
  },
  "tagline" : "You Know, for Search"
}

Add "cluster_name" value as "elasticsearch.clustername" in ur application.properties: example values in application.properties:

elasticsearch.clustername =docker-cluster
elasticsearch.host =localhost
elasticsearch.port =9300

to make sure that transport client in up and running in your elastic search execute below command from terminal: curl -XGET http://localhost:9300 this should give you below reply : "This is not a HTTP port"

(please install curl if u r on windows)

this means your cluster is up and running.

Add below dependancy in your pom.xml:

<dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-elasticsearch</artifactId>
</dependency>

This should fetch the proper spring data elastic dependancy to your spring project. Change your transport client declaration to one used below:

  TransportClient client = new PreBuiltTransportClient(esSettings)
            .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(EsHost), EsPort));

Above configs should work fine. if you are running elastic search via docker. then make sure that your command to run the docker image is as below. this take care of the host mappings and disable xpack security.

docker run -p 9200:9200 -p 9300:9300 -e "http.host=0.0.0.0" -e "transport.host=0.0.0.0" -e "xpack.security.enabled=false" docker.elastic.co/elasticsearch/elasticsearch:5.5.3