Search code examples
elasticsearchspring-data-elasticsearch

Spring Data Elasticsearch - how to use ElasticsearchRestTemplate?


I have a springboot app which connects to ElasticSearch. However I would like to use ElasticsearchRestTemplate and I get only classNotFound.

My pom.xml

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.5.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <dependencies>
            <dependency>
                <groupId>org.springframework.data</groupId>
                <artifactId>spring-data-elasticsearch</artifactId>
                <version>3.1.2.RELEASE</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
            </dependency>
     <dependencies>

And when I try to do import

import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;

It shows that the class does not exist. How to solve that ? Which version of Spring Elasticsearch Data to be able to use ElasticsearchRestTemplate ?


Solution

  • ElasticsearchRestTemplate is part of release 4 of Spring Data ES which is still under development.

    If you want to try it out (i.e. not in production) you can use the 4.0.0.BUILD-SNAPSHOT version.