◉◡◉ 您好,欢迎到访伊成个人站!

ElasticSearch-实战代码3

本文于1776天之前发表,文中内容可能已经过时。

“ElasticSearch-实战代码3”

前言

学习了几天ElasticSearch,简单的做了一个实战项目,把学习过程中的各个用法简单的在项目里面体现出来。

开发环境

IntelliJ IDEA , JDK 1.8

ElasticSearch版本

5.6.2

前端页面模块

采用的是 闲言轻博客模板 (https://fly.layui.com/store/layuiXianyan/

技术栈

spring boot , elasticSearch , layui …
为了让大家更加直观的看见本项目中使用的版本,直接把项目里面的pom.xml 文件给提供出来!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?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>

<groupId>com.lvoyee</groupId>
<artifactId>esblog</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>esblog</name>
<description>lvoyee_es_blog</description>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.2.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<!--<thymeleaf.version>3.0.2.RELEASE</thymeleaf.version>
<thymeleaf-layout-dialect.version>2.1.1</thymeleaf-layout-dialect.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-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.elasticsearch.plugin</groupId>
<artifactId>transport-netty3-client</artifactId>
<version>5.6.10</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>3.3.1</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.7</version>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>

代码结构截图

“ElasticSearch-实战代码3”

项目运行截图

首页
“ElasticSearch-实战代码3”

登录
“ElasticSearch-实战代码3”

文章详情
“ElasticSearch-实战代码3”

已经完成的功能

1.登录
2.首页
3.文章显示
4.点赞
5.关于

未完成的功能

1.退出
2.留言
3.搜索

项目如何启动

在启动项目之前,务必需要安装好了 elasticsearch,必要的环境细节不多赘述了。

1.找到 elasticsearch 的bin目录下面的 elasticsearch.bat
2.启动 grunt servet
3.找到项目的 EsblogApplication 启动即可

访问 http://localhost:8080

mapping结构

关于的mapping

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
{
"mappings": {
"about": {
"dynamic": false,
"properties": {
"title": {
"type": "text"
},
"content": {
"type": "text"
},
"num": {
"type": "integer"
},
},
"likenum":{
"type":"integer"
}
}
}
}
}

登录用户的mapping

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
"mappings": {
"user": {
"properties": {
"password": {
"type": "text"
},
"nickName": {
"type": "text"
},
"sex": {
"type": "integer"
},
"userName": {
"type": "text"
},
"createDate": {
"format": "yyyy-MM-dd || epoch_millis",
"type": "date"
}
}
}
}

文章的mapping

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
{

"mappings":{
"article":{
"properties":{
"like":{
"type": "integer"
},
"author":{
"type": "text"
},
"title":{
"type": "text"
},
"content":{
"type":"text"
},
"publish_date":{
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss || yyyy-MM-dd || epoch_millis"
}
}
}
}
}

小结

在这个项目中所有的后台功能都是基于elasticsearch 做的,目的就是为了学习如何用 elasticsearch 做数据的 CURD,仅此而已。

还有一些未完成的功能,希望看了我写的代码可以自行学习补加完成,该项目本着学习 elasticsearch 的使用制作而成,多又瑕疵,还望多多包涵。

需要源码的小伙伴,可以加入QQ群领取即可!

支付宝打赏 微信打赏