Spring Data and Elasticsearch 5.2 Transportclient error

I am experimenting with Spring Data Elasticsearch and also have a local Elasticsearch 5.2 running. Somehow can't connect from the application to the ES instance. My Repository XML looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"      
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
       xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch http://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch-1.0.xsd
		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

	<context:annotation-config/>
	<bean name="mainBean" class="com.searchtemplate.SpringElasticsearchExample"/>
 
    <elasticsearch:repositories base-package="com.searchtemplate"/>
    <!-- <elasticsearch:node-client id="client" local="true"/> -->
    <elasticsearch:transport-client id="client" cluster-nodes="localhost:9300" cluster-name="mycluster" />

    <bean name="elasticsearchTemplate" class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
        <constructor-arg name="client" ref="client"/>
    </bean>
</beans>

Error in Eclipse console:

70 [main] INFO org.springframework.context.support.ClassPathXmlApplicationContext - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@e2144e4: startup date [Tue Feb 14 13:28:39 CET 2017]; root of context hierarchy
102 [main] INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [applicationContext.xml]
428 [main] INFO org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
583 [main] INFO org.elasticsearch.plugins - [Agent X] modules [], plugins [], sites []
1075 [main] INFO org.springframework.data.elasticsearch.client.TransportClientFactoryBean - adding transport node : localhost:9300
1261 [elasticsearch[Agent X][generic][T#2]] INFO org.elasticsearch.client.transport - [Agent X] failed to get local cluster state for {#transport#-1}{127.0.0.1}{127.0.0.1:9300}, disconnecting...
NodeDisconnectedException[[][127.0.0.1:9300][cluster:monitor/state] disconnected]
1547 [main] WARN org.springframework.context.support.ClassPathXmlApplicationContext - Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mainBean': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.searchtemplate.EmployeeRepository com.searchtemplate.SpringElasticsearchExample.repository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'employeeRepository': Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.springframework.core.annotation.AnnotatedElementUtils.findMergedAnnotation(Ljava/lang/reflect/AnnotatedElement;Ljava/lang/Class;)Ljava/lang/annotation/Annotation;
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1202)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
	at com.searchtemplate.SpringElasticsearchExample.main(SpringElasticsearchExample.java:23)

Error in Elasticsearch log:

[2017-02-14T13:28:41,029][WARN ][o.e.t.n.Netty4Transport  ] [mDgzuve] exception caught on transport layer [[id: 0xa238d207, L:/127.0.0.1:9300 - R:/127.0.0.1:42102]], closing connection
java.lang.IllegalStateException: Received message from unsupported version: [2.0.0] minimal compatible version is: [5.0.0]
	at org.elasticsearch.transport.TcpTransport.messageReceived(TcpTransport.java:1236) ~[elasticsearch-5.1.2.jar:5.1.2]
	at org.elasticsearch.transport.netty4.Netty4MessageChannelHandler.channelRead(Netty4MessageChannelHandler.java:74) ~[transport-netty4-5.1.2.jar:5.1.2]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:373) [netty-transport-4.1.6.Final.jar:4.1.6.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:359) 

......

It all work when I change

<elasticsearch:repositories base-package="com.searchtemplate"/> to
<elasticsearch:node-client id="client" local="true"/>

but ofcourse I want to work with a real Elasticsearch instance.

What might be the cause of this?

Probably spring data project comes with a 5.0.0 instead of 5.2.0 client?

May be force that in your pom file?

1 Like

thanks for your response. I checked. Unfortunately Spring Data is only compatible with 2.X versions and not 5.X of ES. Could I have missed something? I have the following latest dependencies of Spring Data Elasticsearch.

<dependency>
	<groupId>org.springframework</groupId>
	<artifactId>spring-core</artifactId>
	<version>4.3.6.RELEASE</version>
</dependency>
<dependency>
	<groupId>org.springframework</groupId>
	<artifactId>spring-context</artifactId>
	<version>4.3.6.RELEASE</version>
</dependency>
<dependency>
	<groupId>org.springframework.data</groupId>
	<artifactId>spring-data-elasticsearch</artifactId>
	<version>2.1.0.RELEASE</version>
</dependency>

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