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的更多相关文章

  1. springboot2.0+websocket集成【群发消息+单对单】(二)

    https://blog.csdn.net/qq_21019419/article/details/82804921 版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上 ...

  2. springboot2.1.3集成webservice及错误No operation was found with the name {...}解决办法

    1.项目使用springboot 2.1.3版本,集成webservice使用的依赖如下 <parent> <groupId>org.springframework.boot& ...

  3. springboot集成spring data ElasticSearch

    ES支持SpringBoot使用类似于Spring Data Jpa的方式查询,使得查询更加方便. 1.依赖引入 compile “org.springframework.boot:spring-bo ...

  4. SpringBoot(十六):SpringBoot2.1.1集成fastjson,并使用fastjson替代默认的MappingJackson

    springboot2.1.1默认采用的json converter是MappingJackson,通过调试springboot项目中代码可以确定这点.在springboot项目中定义WebMvcCo ...

  5. springboot2.0+swagger集成

    场景:项目中添加Swagger配置,可以加速项目的开发,在快速开发项目中十分重要. 1.pom.xml添加swagger <!--swagger --> <dependency> ...

  6. springboot2.7.x 集成log4j2配置写入日志到mysql自定义表格

    在阅读之前请先查看[springboot集成log4j2] 本文暂不考虑抽象等实现方式,只限于展示如何自定义配置log4j2并写入mysql数据库(自定义结构) 先看下log4j2的配置 <?x ...

  7. springboot2.1.3集成单节点elasticsearch6.4.0

    本案例写了一个关于医生医院搜索的例子,包括求和模式下的打分(分值与相关性有关)搜索,单节点时切勿配置节点名称和节点ip.github地址:https://github.com/zhzhair/spri ...

  8. springboot2.0 快速集成kafka

    一.kafka搭建 参照<kafka搭建笔记> 二.版本 springboot版本 <parent> <groupId>org.springframework.bo ...

  9. springboot2整合zookeeper集成curator

    步骤: 1- pom.xml <dependency> <groupId>org.apache.curator</groupId> <artifactId&g ...

随机推荐

  1. ConstraintLayout 学习笔记

    如何阅读 xml 属性 与 Relativelayout 不同,ConstrainLayout 的属性需要同时说明需要怎么操作自己与目标控件,例如:layout_constraintLeft_toLe ...

  2. 痞子衡嵌入式:MCUXpresso IDE下SDK工程导入与workspace管理机制

    大家好,我是痞子衡,是正经搞技术的痞子.今天痞子衡给大家介绍的是MCUXpresso IDE下SDK工程导入与workspace管理机制. MCUXpresso IDE是恩智浦软件团队倾注很大心血研发 ...

  3. feig中调用其他微服务接口无反应

    1.调用微服务时get请求接口中不能使用@RequestBody注解,不然接口调用无反应.post接口中可以使用@RequestBody注解

  4. Linux嵌入式学习-交叉编译mplayer

    http://bbs.gkong.com/archive.aspx?ID=286721

  5. Java学习日报7.13

    /** * *//** * @author 86152 * */package Employee;import java.util.Scanner;public class Employee{ pri ...

  6. 关于HashSet

    HashSet存储数据原理: 当HashSet调用add方法时,有返回值,返回值是boolean类型,表示是否添加成功(如果对象不存在,则添加成功,否则添加失败) 但是,添加的过程并不是一个个去遍历去 ...

  7. dotnet高性能buffer

    1 前言 我曾经写过<杂谈.netcore的Buffer相关新类型>的博客,简单介绍过BinaryPrimitives.Span<>,Memory<>,ArrayP ...

  8. Mac安装homebrew,postman,charles

    Homebrew是一款Mac OS平台下的软件包管理工具,拥有安装.卸载.更新.查看.搜索等很多实用的功能.简单的一条指令,就可以实现包管理,而不用你关心各种依赖和文件路径的情况,十分方便快捷. 1. ...

  9. 【数据库】MySQL & SQL 介绍

    文章目录 MySQL & SQL 介绍 1.MySQL的背景 2.MySQL的优点 3.MySQL的安装 4.MySQL服务的启动和停止 方式一 方式二 5.MySQL服务的登录和退出 方式一 ...

  10. Spring Cloud微服务Sentinel+Apollo限流、熔断实战总结

    在Spring Cloud微服务体系中,由于限流熔断组件Hystrix开源版本不在维护,因此国内不少有类似需求的公司已经将眼光转向阿里开源的Sentinel框架.而以下要介绍的正是作者最近两个月的真实 ...