forked from xkcoding/spring-boot-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
379 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,69 @@ | ||
<?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>spring-boot-demo-elasticsearch</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>spring-boot-demo-elasticsearch</name> | ||
<description>Demo project for Spring Boot</description> | ||
|
||
<parent> | ||
<groupId>com.xkcoding</groupId> | ||
<artifactId>spring-boot-demo</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | ||
<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-web</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<finalName>spring-boot-demo-elasticsearch</finalName> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>spring-boot-demo-elasticsearch</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>spring-boot-demo-elasticsearch</name> | ||
<description>Demo project for Spring Boot</description> | ||
|
||
<parent> | ||
<groupId>com.xkcoding</groupId> | ||
<artifactId>spring-boot-demo</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | ||
<java.version>1.8</java.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter</artifactId> | ||
</dependency> | ||
|
||
<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> | ||
|
||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<optional>true</optional> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>cn.hutool</groupId> | ||
<artifactId>hutool-all</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.google.guava</groupId> | ||
<artifactId>guava</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<finalName>spring-boot-demo-elasticsearch</finalName> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...-boot-demo-elasticsearch/src/main/java/com/xkcoding/elasticsearch/constants/EsConsts.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.xkcoding.elasticsearch.constants; | ||
|
||
/** | ||
* <p> | ||
* ES常量池 | ||
* </p> | ||
* | ||
* @package: com.xkcoding.elasticsearch.constants | ||
* @description: ES常量池 | ||
* @author: yangkai.shen | ||
* @date: Created in 2018-12-20 17:30 | ||
* @copyright: Copyright (c) 2018 | ||
* @version: V1.0 | ||
* @modified: yangkai.shen | ||
*/ | ||
public interface EsConsts { | ||
/** | ||
* 索引名称 | ||
*/ | ||
String INDEX_NAME = "person"; | ||
|
||
/** | ||
* 类型名称 | ||
*/ | ||
String TYPE_NAME = "person"; | ||
} |
67 changes: 67 additions & 0 deletions
67
spring-boot-demo-elasticsearch/src/main/java/com/xkcoding/elasticsearch/model/Person.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.xkcoding.elasticsearch.model; | ||
|
||
import com.xkcoding.elasticsearch.constants.EsConsts; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.elasticsearch.annotations.Document; | ||
import org.springframework.data.elasticsearch.annotations.Field; | ||
import org.springframework.data.elasticsearch.annotations.FieldType; | ||
|
||
import java.util.Date; | ||
|
||
/** | ||
* <p> | ||
* 用户实体类 | ||
* </p> | ||
* | ||
* @package: com.xkcoding.elasticsearch.model | ||
* @description: 用户实体类 | ||
* @author: yangkai.shen | ||
* @date: Created in 2018-12-20 17:29 | ||
* @copyright: Copyright (c) 2018 | ||
* @version: V1.0 | ||
* @modified: yangkai.shen | ||
*/ | ||
@Document(indexName = EsConsts.INDEX_NAME, type = EsConsts.TYPE_NAME, shards = 1, replicas = 0) | ||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class Person { | ||
/** | ||
* 主键 | ||
*/ | ||
@Id | ||
private Long id; | ||
|
||
/** | ||
* 名字 | ||
*/ | ||
@Field(type = FieldType.Keyword) | ||
private String name; | ||
|
||
/** | ||
* 国家 | ||
*/ | ||
@Field(type = FieldType.Keyword) | ||
private String country; | ||
|
||
/** | ||
* 年龄 | ||
*/ | ||
@Field(type = FieldType.Integer) | ||
private Integer age; | ||
|
||
/** | ||
* 生日 | ||
*/ | ||
@Field(type = FieldType.Date) | ||
private Date birthday; | ||
|
||
/** | ||
* 介绍 | ||
*/ | ||
@Field(type = FieldType.Text, analyzer = "ik_smart") | ||
private String remark; | ||
} |
31 changes: 31 additions & 0 deletions
31
...o-elasticsearch/src/main/java/com/xkcoding/elasticsearch/repository/PersonRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.xkcoding.elasticsearch.repository; | ||
|
||
import com.xkcoding.elasticsearch.model.Person; | ||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* <p> | ||
* 用户持久层 | ||
* </p> | ||
* | ||
* @package: com.xkcoding.elasticsearch.repository | ||
* @description: 用户持久层 | ||
* @author: yangkai.shen | ||
* @date: Created in 2018-12-20 19:00 | ||
* @copyright: Copyright (c) 2018 | ||
* @version: V1.0 | ||
* @modified: yangkai.shen | ||
*/ | ||
public interface PersonRepository extends ElasticsearchRepository<Person, Long> { | ||
|
||
/** | ||
* 根据年龄区间查询 | ||
* | ||
* @param min 最小值 | ||
* @param max 最大值 | ||
* @return 满足条件的用户列表 | ||
*/ | ||
List<Person> findByAgeBetween(Integer min, Integer max); | ||
} |
5 changes: 3 additions & 2 deletions
5
spring-boot-demo-elasticsearch/src/main/resources/application.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
spring: | ||
data: | ||
elasticsearch: | ||
cluster-name: elasticsearch | ||
cluster-nodes: 127.0.0.1:9300 | ||
#cluster-name: elasticsearch | ||
cluster-name: metadata_es | ||
cluster-nodes: 192.168.241.19:9300 |
Oops, something went wrong.