springboot2.2.2集成6.5 Elasticsearch
1.0POM文件
<!-- spring-boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</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-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
<scope>compile</scope>
</dependency> <!-- elasticSearch -->
<!-- es核心jar包 -->
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency> <dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-elasticsearch</artifactId>
</dependency>
2.YML文件
spring:
profiles:
active: dev-win
redis:
database: 0
host: xxx
lettuce:
pool:
max-active: 10
max-idle: 10
max-wait: 5000ms
min-idle: 5
password: ''
port: 6379
timeout: 3000
session:
redis:
flush-mode: on_save
namespace: clearing
store-type: redis
timeout: 86400
data:
elasticsearch:
cluster-nodes: 192.168.1.234:9300
cluster-name: docker-cluster
repositories:
enabled: true
3.domain
@Document(indexName = "test-boot",type = "goods",shards = 1,replicas = 0, refreshInterval = "-1")
@Data
public class Elastic implements Serializable {
@Id
private String id;
@Field
private String name;
@Field
private String content;
@Field
private String price;
}
4.Dao
@Component
public interface ESDao extends ElasticsearchRepository<Elastic, String> {
Elastic queryEmployeeById(String id);
}
5.controller
@RestController
@RequestMapping("/es")
public class ElasticSearchController { @Autowired
private ESDao er; //增加
@RequestMapping("/add/{id}")
public String add(@PathVariable("id")String id){ Elastic employee=new Elastic();
employee.setId(id);
employee.setName("Y.S.K");
employee.setContent("ooo");
employee.setPrice("26");
er.save(employee); System.err.println("add a obj");
return "success";
} //删除
@RequestMapping("/delete")
public String delete(){
Elastic employee=new Elastic();
employee.setId("1");
er.delete(employee); return "success";
} //局部更新
@RequestMapping("/update")
public String update(){ Elastic employee=er.queryEmployeeById("1");
employee.setName("哈哈");
er.save(employee); System.err.println("update a obj"); return "success";
} //查询
@RequestMapping("/query/{id}")
public Elastic query(@PathVariable("id")String id){ Elastic accountInfo=er.queryEmployeeById(id);
System.err.println(JSONUtil.parseObj(accountInfo)); return accountInfo;
} }
springboot2.2.2集成6.5 Elasticsearch的更多相关文章
- springboot2.0+websocket集成【群发消息+单对单】(二)
https://blog.csdn.net/qq_21019419/article/details/82804921 版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上 ...
- springboot2.1.3集成webservice及错误No operation was found with the name {...}解决办法
1.项目使用springboot 2.1.3版本,集成webservice使用的依赖如下 <parent> <groupId>org.springframework.boot& ...
- springboot集成spring data ElasticSearch
ES支持SpringBoot使用类似于Spring Data Jpa的方式查询,使得查询更加方便. 1.依赖引入 compile “org.springframework.boot:spring-bo ...
- SpringBoot(十六):SpringBoot2.1.1集成fastjson,并使用fastjson替代默认的MappingJackson
springboot2.1.1默认采用的json converter是MappingJackson,通过调试springboot项目中代码可以确定这点.在springboot项目中定义WebMvcCo ...
- springboot2.0+swagger集成
场景:项目中添加Swagger配置,可以加速项目的开发,在快速开发项目中十分重要. 1.pom.xml添加swagger <!--swagger --> <dependency> ...
- springboot2.7.x 集成log4j2配置写入日志到mysql自定义表格
在阅读之前请先查看[springboot集成log4j2] 本文暂不考虑抽象等实现方式,只限于展示如何自定义配置log4j2并写入mysql数据库(自定义结构) 先看下log4j2的配置 <?x ...
- springboot2.1.3集成单节点elasticsearch6.4.0
本案例写了一个关于医生医院搜索的例子,包括求和模式下的打分(分值与相关性有关)搜索,单节点时切勿配置节点名称和节点ip.github地址:https://github.com/zhzhair/spri ...
- springboot2.0 快速集成kafka
一.kafka搭建 参照<kafka搭建笔记> 二.版本 springboot版本 <parent> <groupId>org.springframework.bo ...
- springboot2整合zookeeper集成curator
步骤: 1- pom.xml <dependency> <groupId>org.apache.curator</groupId> <artifactId&g ...
随机推荐
- 【Azure App Service】C#下制作的网站,所有网页本地测试运行无误,发布至Azure之后,包含CHART(图表)的网页打开报错,错误消息为 Runtime Error: Server Error in '/' Application
问题描述 C#下制作的网站,所有网页本地测试运行无误,发布至Azure之后,包含CHART(图表)的网页打开报错,错误消息为 Runtime Error: Server Error in '/' Ap ...
- Ubuntu安装 Sublime Text 及常用插件推荐
之前一直在用 Code Blocks 这个IDE工具,可用着还是感觉不怎么好,于是在网上找到了一篇文章,上面介绍了不少IDE,我找到了Sublime Text 感觉挺不错的. 帖子地址: http:/ ...
- ArrayListHashmap嵌套
package arrayListHashMap; import java.util.ArrayList; import java.util.HashMap; import java.util.Map ...
- [剑指 Offer 11. 旋转数组的最小数字]
[剑指 Offer 11. 旋转数组的最小数字] 把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转.输入一个递增排序的数组的一个旋转,输出旋转数组的最小元素.例如,数组 [3,4,5, ...
- 【函数分享】每日PHP函数分享(2021-1-12)
str_pad() 使用另一个字符串填充字符串为指定长度 . string str_pad ( string $input, int $pad_length[, string $pad_string= ...
- 如果生成allure报告过程中报错AttributeError: module 'allure' has no attribute 'severity_level'
1.pip uninstall pytest-allure-adaptor 2.pip install allure-pytest 3.搞定 快去吃饭吧
- 【MySQL 基础】MySQL必知必会
MySQL必知必会 简介 <MySQL必知必会>的学习笔记和总结. 书籍链接 了解SQL 数据库基础 什么是数据库 数据库(database):保存有组织的数据的容器(通常是一个文 件或一 ...
- 十三:SQL注入之MYSQL注入
MYSQL注入中首先要明确当前注入点权限,高权限注入时有更多的攻击手法,有的能直接进行getshell操作,其中也会遇到很多的阻碍,相关防御手法也要明确,所谓知己知彼,百战不殆.作为安全开发工作者,攻 ...
- select 里面带的值居然是估算的?
mysql> set profiling=1;Query OK, 0 rows affected, 1 warning (0.07 sec) mysql> select count(1) ...
- 【MySQL】SELECT语句 - 查询数据
第4章 检索数据 文章目录 第4章 检索数据 1.SELECT语句 2.检索单个列 3.检索多个列 4.检索所有列 5.检索不同的行 6.限制结果 7.使用完全限定的表名 8.小结 简单记录 - My ...