Connecting to ElasticSearch using Java API


#1

We are trying to connect to elastic search 2.1.1 version , by creating a client class in spring . Added the required dependencies as folows,

org.elasticsearch elasticsearch 2.1.1
	<dependency>
		<groupId>org.springframework.data</groupId>
		<artifactId>spring-data-elasticsearch</artifactId>
		<exclusions>
			<exclusion>
				<groupId>org.elasticsearch</groupId>
				<artifactId>elasticsearch</artifactId>
			</exclusion>
		</exclusions>
		<version>1.3.4.RELEASE</version>
	</dependency>

The client class is as follows,

@Configuration
@EnableElasticsearchRepositories(basePackages = "com.abc.test.elasticsearch")
public class ElasticSearchConfig {

 @Bean public ElasticsearchOperations elasticsearchTemplate() { 
	 System.getProperties().setProperty("es.path.home", "C:\\elasticsearch-2.1.1");
	 return new ElasticsearchTemplate(NodeBuilder.nodeBuilder().local(true).node().client()); 
 }

}

It's throwing the following exception.

Caused by: java.lang.NoSuchMethodError: com.fasterxml.jackson.dataformat.yaml.YAMLFactory._decorate(Ljava/io/Reader;Lcom/fasterxml/jackson/core/io/IOContext;)Ljava/io/Reader;
at com.fasterxml.jackson.dataformat.yaml.YAMLFactory.createParser(YAMLFactory.java:327) ~[jackson-dataformat-yaml-2.6.2.jar:2.6.2]
at org.elasticsearch.common.xcontent.yaml.YamlXContent.createParser(YamlXContent.java:90) ~[elasticsearch-2.1.1.jar:2.1.1]
at org.elasticsearch.common.settings.loader.XContentSettingsLoader.load(XContentSettingsLoader.java:44) ~[elasticsearch-2.1.1.jar:2.1.1]
at org.elasticsearch.common.settings.loader.YamlSettingsLoader.load(YamlSettingsLoader.java:46) ~[elasticsearch-2.1.1.jar:2.1.1]
at org.elasticsearch.common.settings.Settings$Builder.loadFromStream(Settings.java:1074) ~[elasticsearch-2.1.1.jar:2.1.1]
at org.elasticsearch.common.settings.Settings$Builder.loadFromPath(Settings.java:1061) ~[elasticsearch-2.1.1.jar:2.1.1]
at org.elasticsearch.node.internal.InternalSettingsPreparer.prepareEnvironment(InternalSettingsPreparer.java:88) ~[elasticsearch-2.1.1.jar:2.1.1]
at org.elasticsearch.node.Node.(Node.java:128) ~[elasticsearch-2.1.1.jar:2.1.1]
at org.elasticsearch.node.NodeBuilder.build(NodeBuilder.java:145) ~[elasticsearch-2.1.1.jar:2.1.1]
at org.elasticsearch.node.NodeBuilder.node(NodeBuilder.java:152) ~[elasticsearch-2.1.1.jar:2.1.1]
at com.mps.pharmacy.config.ElasticSearchConfig.elasticsearchTemplate(ElasticSearchConfig.java:24) ~[classes/:na]

Could you please let me know what dependency is missing , or what is wrong with my client class.


(David Pilato) #2

I don't think that spring data has been updated to 2.x series.


(system) #3