ElasticSearch是个开源分布式搜索引擎,提供搜集、分析、存储数据三大功能。它的特点有:分布式,零配置,自动发现,索引自动分片,索引副本机制,restful风格接口,多数据源,自动搜索负载等。主要负责将日志索引并存储起来,方便业务方检索查询。
(资料图片仅供参考)
下载地址:https://www.elastic.co/cn/downloads/elasticsearch
选择Windows版本,我下载的是7.17.0。解压后即可完成安装。
进入bin文件, 双击执行 elasticsearch.bat,然后打开浏览器,进入页面: http://localhost:9200,看到以下输出,表示启动成功。
项目GitHub地址:https://github.com/Snowstorm0/learn-es
项目Gitee地址:https://gitee.com/Snowstorm0/learn-es
public class RestClientConfig extends AbstractElasticsearchConfiguration { @Override @Bean public RestHighLevelClient elasticsearchClient() { final ClientConfiguration clientConfiguration = ClientConfiguration.builder() .connectedTo("localhost:9200") .build(); return RestClients.create(clientConfiguration).rest(); }}
public class UserEntity { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Integer id; private String name; private String job; private Double deposit; private Date processTime = new Date();}
配置完成后,ElasticSearch即可像常规的数据库那样进行增删改查的操作。
spring.datasource.username=rootspring.datasource.password=rootspring.datasource.url=jdbc:mysql://localhost:3306/sys?characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC
调用添加接口:http://localhost:8080/user/add
添加User类的请求体:
{ "id":"1", "name":"代码的路", "job":"码农", "deposit":100.0}
可以看到添加成功:
运行读取接口:http://localhost:8080/user/search/whole?key=码农
可以获得刚写入的User类,是完整结构:
运行读取接口:http://localhost:8080/user/search/es?key=码农
可以获得刚写入的User类,只有User结构:
打开数据库,无需手动创建表结构,即可看到User类也已经写入到数据库中:
因此可以刻直接从数据库读取。
X 关闭
2023-03-23 15:05:41
2023-03-23 14:59:56
2023-03-23 14:04:03
2023-03-23 12:20:32
2023-03-23 10:53:25
2023-03-23 09:43:55
2023-03-23 08:10:54
2023-03-23 07:12:03
2023-03-23 04:18:00
2023-03-22 23:54:34
2023-03-22 20:51:43
2023-03-22 19:08:31
2023-03-22 19:03:35
2023-03-22 17:08:14
2023-03-22 16:07:43
2023-03-22 14:55:42
2023-03-22 12:49:16
2023-03-22 10:46:14
2023-03-22 08:51:17
2023-03-22 05:44:30
2023-03-22 01:00:52
2023-03-21 21:03:27
2023-03-21 18:58:33
2023-03-21 14:49:38
2023-03-21 12:58:20
2023-03-21 10:42:05
2023-03-21 09:08:44
2023-03-21 05:50:20
2023-03-21 00:57:39
2023-03-20 21:54:38
2023-03-20 18:51:39
2023-03-20 16:58:25
2023-03-20 14:58:16
2023-03-20 12:53:52
2023-03-20 10:41:25
2023-03-20 08:51:19
2023-03-20 04:45:00
2023-03-19 23:53:59
2023-03-19 20:01:12
2023-03-19 16:06:23
2023-03-19 12:40:16
2023-03-19 08:59:54
2023-03-19 05:00:16
2023-03-19 04:47:28
2023-03-18 23:18:33
2023-03-18 19:44:15
2023-03-18 15:56:39
2023-03-18 13:02:48
2023-03-18 09:52:31
2023-03-18 06:06:02
2023-03-18 00:55:35
2023-03-17 21:47:49
2023-03-17 19:04:30
2023-03-17 16:53:44
2023-03-17 14:51:09
2023-03-17 11:57:53
2023-03-17 10:09:18
2023-03-17 08:12:14
2023-03-17 04:49:10
2023-03-16 23:52:24
2023-03-16 20:24:55
2023-03-16 18:04:51
2023-03-16 16:11:16
2023-03-16 14:06:56
2023-03-16 11:48:57
2023-03-16 10:06:22
2023-03-16 08:15:03
2023-03-16 04:03:14
2023-03-15 23:01:10
2023-03-15 20:22:04
2023-03-15 17:42:47
2023-03-15 15:55:24
2023-03-15 13:50:10
2023-03-15 11:20:21
2023-03-15 09:25:37
2023-03-15 07:00:51
2023-03-15 02:15:01
2023-03-14 21:47:22
2023-03-14 19:16:21
2023-03-14 16:53:51
2023-03-14 14:42:56
2023-03-14 12:32:15
2023-03-14 10:26:49
2023-03-14 08:17:36
2023-03-14 03:10:12
2023-03-13 22:09:22
2023-03-13 19:12:21
2023-03-13 16:47:43
2023-03-13 14:49:00
2023-03-13 11:44:37
2023-03-13 10:04:51
2023-03-13 07:00:52
2023-03-13 01:00:09
2023-03-12 20:14:14
2023-03-12 16:52:44
2023-03-12 13:03:34
2023-03-12 09:12:09
2023-03-12 03:55:58
2023-03-11 21:51:26
2023-03-11 18:05:55
Copyright © 2015-2022 南方化工网版权所有 备案号:粤ICP备18023326号-21 联系邮箱:855 729 8@qq.com