Spring Boot + Spring Data + Elasticsearch instance
In this article, we'll discuss "how to create a spring Boot + spring Data + Elasticsearch sample".
The tools used in this article:
Spring Boot 1.5.1.RELEASE
Spring Boot Starter Data Elasticsearch 1.5.1.RELEASE
Spring Data Elasticsearch 2.10.RELEASE
Elasticsearch 2.4.4
Maven
Java 8
Attention
Springboot 1.5.1.RELEASE and Spring Data Elasticsearch 2.10.RELEASE only support Elasticsearch 2.4.0. They do not support the latest version of the Elasticsearch 5.x version.
Additional: Spring boot is currently available to operate ES with spring data. However, there are strict requirements on the version. (This sentence is not the original text, reduce the pit)
1. Project structure
A standard MAVEN project structure.
2. Project Dependencies
Configure Spring-boot-starter-data-elasticsearch for spring Data ElasticSearch application.
Pom.xml
<?xml version= "1.0" encoding= "UTF-8"?>
<project xmlns= "http://maven.apache.org/POM/4.0.0"
Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"
Xsi:schemalocation= "http://maven.apache.org/POM/4.0.0
Http://maven.apache.org/xsd/maven-4.0.0.xsd ">
<modelVersion>4.0.0</modelVersion>
<artifactId>springboot-springdata-elasticsearch-example</artifactId>
<packaging>jar</packaging>
<url>https://www.mkyong.com</url>
<version>1.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.1.RELEASE</version>
</parent>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--Runtime, for Embedded Elasticsearch,
Comment this if connect to external elastic search server-->
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!--package as a executable Jar/war--
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactid>spring-boot-maven-plugin