Damien Gallagher
Damien Gallagher

Reputation: 585

Spring Boot Elastic Search And Not Able to Connect

I was following this tutorial on the Mkyong site https://www.mkyong.com/spring-boot/spring-boot-spring-data-elasticsearch-example/

It uses the spring-boot-starter-data-elasticsearch library to connect to elasticSearch

I was using the following details to try and connect to an elastic search instance on Amazon`

elasticsearch.host=<search address in amazon elastic search console>
elasticsearch.port=9200
elasticsearch.clustername=<accountId:clusterName>`

However I keep getting the following errors

 2017-05-16 18:37:24.308  INFO 7108 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Overriding bean definition for bean 'elasticsearchTemplate' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=esConfig; factoryMethodName=elasticsearchTemplate; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [com/mkyong/EsConfig.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchDataAutoConfiguration; factoryMethodName=elasticsearchTemplate; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataAutoConfiguration.class]]
2017-05-16 18:37:24.859  INFO 7108 --- [           main] org.elasticsearch.plugins                : [Rawhide Kid] modules [], plugins [], sites []
2017-05-16 18:37:46.911  INFO 7108 --- [           main] org.elasticsearch.client.transport       : [Rawhide Kid] failed to connect to node [{#transport#-1}{55.66.223.158}{55.66.223.158:9200}], removed from nodes list

org.elasticsearch.transport.ConnectTransportException: [][55.66.223.158:9200] connect_timeout[30s]
    at org.elasticsearch.transport.netty.NettyTransport.connectToChannelsLight(NettyTransport.java:967) ~[elasticsearch-2.4.4.jar:2.4.4]
    at org.elasticsearch.transport.netty.NettyTransport.connectToNode(NettyTransport.java:933) ~[elasticsearch-2.4.4.jar:2.4.4]
    at org.elasticsearch.transport.netty.NettyTransport.connectToNodeLight(NettyTransport.java:906) ~[elasticsearch-2.4.4.jar:2.4.4]
    at org.elasticsearch.transport.TransportService.connectToNodeLight(TransportService.java:267) ~[elasticsearch-2.4.4.jar:2.4.4]
    at org.elasticsearch.client.transport.TransportClientNodesService$SimpleNodeSampler.doSample(TransportClientNodesService.java:390) ~[elasticsearch-2.4.4.jar:2.4.4]
    at org.elasticsearch.client.transport.TransportClientNodesService$NodeSampler.sample(TransportClientNodesService.java:336) [elasticsearch-2.4.4.jar:2.4.4]
    at org.elasticsearch.client.transport.TransportClientNodesService.addTransportAddresses(TransportClientNodesService.java:187) [elasticsearch-2.4.4.jar:2.4.4]
    at org.elasticsearch.client.transport.TransportClient.addTransportAddress(TransportClient.java:243) [elasticsearch-2.4.4.jar:2.4.4]
    at com.mkyong.EsConfig.client(EsConfig.java:45) [classes/:na]
    at com.mkyong.EsConfig$$EnhancerBySpringCGLIB$$7e0ccfee.CGLIB$client$0(<generated>) [classes/:na]
    at com.mkyong.EsConfig$$EnhancerBySpringCGLIB$$7e0ccfee$$FastClassBySpringCGLIB$$83a2b819.invoke(<generated>) [classes/:na]
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) [spring-core-4.3.6.RELEASE.jar:4.3.6.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:356) [spring-context-4.3.6.RELEASE.jar:4.3.6.RELEASE]
    at com.mkyong.EsConfig$$EnhancerBySpringCGLIB$$7e0ccfee.client(<generated>) [classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_65]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_65]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_65]
    at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_65]
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instant

Any ideas what I need to do to connect to an elastic search instance on Amazon?

Thanks Damien

Upvotes: 0

Views: 2069

Answers (3)

Aniruddh Rathore
Aniruddh Rathore

Reputation: 229

Use HOST: ip address of hosted AWS elasticsearch or path of hosted AWS es and PORT : 80

Ex:

10.100.1.1 or xyz.abc.com

Upvotes: 0

Yeshodhan Kulkarni
Yeshodhan Kulkarni

Reputation: 2943

AWS Elasticsearch only works on port 80 using Rest API. The default transport API from elasticsearch does not work with Hosted AWS elasticsearch.

I had to customize the Jest client to add additional hooks to sign every request.

You may want to refer to this post on Stack Overflow for more details on how to sign the HTTP request.

Upvotes: 0

Brian Ecker
Brian Ecker

Reputation: 2077

AWS Elasticsearch doesn't support TCP connections, only HTTP connections. This explains why your CURL commands work, but your java connection doesn't work.

TCP transport
The service supports HTTP on port 80, but does not support TCP transport.

http://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/aes-supported-resources.html

https://forums.aws.amazon.com/thread.jspa?messageID=683536

Upvotes: 0

Related Questions