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 ...
随机推荐
- svn忽略idea生成的本地配置文件
为根目录添加svn属性svn:global-ignores 值为 *.iml .idea 多个值之间用换行分隔
- 由两个问题引发的对GaussDB(DWS)负载均衡的思考
摘要:GaussDB(DWS)的负载均衡通过LVS+keepAlived实现.对于这种方式,需要思考的问题是,CN的返回结果是否会经过LVS,然后再返回给前端应用?如果经过LVS,那么,LVS会不会成 ...
- java ListNode 链表
链表是一种数据结构:由数据和指针构成,链表的指针指向下一个节点. java ListNode 链表 就是用Java自定义实现的链表结构. 基本结构: class ListNode { //类名 :Ja ...
- Linux 路由 策略路由
Linux 路由 策略路由 目录 Linux 路由 策略路由 一.路由表 编辑路由表配置文件:/etc/iproute2/rt_tables添加删除修改路由表 二.IP策略 查看IP策略 添加IP策略 ...
- Java基础经典案例
案例列表 01减肥计划switch版本 02减肥计划if版本 03逢七跳过 04不死神兔 05百钱白鸡 06数组元素求和 07判断两个数组是否相同 08查找元素在数组中的索引 09数组元素反转 10评 ...
- 对HTTP请求接口资源下载时间过长的问题分析
问题描述 我司某产品线有指定业务接口customQuery在线上环境中,与首页一起打开时下载数据的时间明显过长(平均可以达到2s) 注: "与首页一起打开" 的含义是指用户进入WE ...
- 6.裸机C语言控制LED
C语言版LED灯 汇编完成C语言的环境配置 C语言完成点亮LED灯 程序编写 汇编程序start.S .global _start /* 全局标号 */ /* * 描述: _start函数,程序从此函 ...
- EasyPoi中@Excel注解中numFormat的使用
需求说明:使用EasyPoi时导出文件中折扣字段是小数,被测试同学提了一个bug,需要转成百分数导出. 个人觉得应该转百分号只要在@Excel注解里面加个属性即可,但是在网上的easypoi教程中没有 ...
- 用python+sklearn(机器学习)实现天气预报数据 模型和使用
用python+sklearn机器学习实现天气预报 模型和使用 项目地址 系列教程 0.前言 1.建立模型 a.准备 引入所需要的头文件 选择模型 选择评估方法 获取数据集 b.建立模型 c.获取模型 ...
- python中列表的insert和append的效率对比
python中insert和append方法都可以向列表中插入数据只不过append默认插入列表的末尾,insert可以指定位置插入元素. 我们来测试一下他俩插入数据的效率: 测试同时对一个列表进行插 ...