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;
} }

最新文章

  1. 继续(3n+1)猜想
  2. jquery 获取元素在浏览器中的绝对位置
  3. css3文字导航鼠标悬停气泡动画特效源码下载
  4. [转帖] Symbol Emotions Sticker 英文符号表情大全
  5. CSS笔记(六)链接
  6. SparkStreaming结合Kafka使用
  7. Mybatis的if test字符串比较问题
  8. Spark RDD概念学习系列之RDD与DSM的异同分析(十三)
  9. SPRING IN ACTION 第4版笔记-第二章-001-用@Autowired\@ComponentScan、@Configuration、@Component实现自动装载bean
  10. c++Socket 异步通讯
  11. Android学习笔记--服务(Service)
  12. 2017级C语言教学总结
  13. SpriteBuilder给节点添加effect在32设备上发生crash
  14. BZOJ_1878_[SDOI2009]HH的项链_莫队
  15. 深度学习之卷积神经网络(CNN)详解与代码实现(二)
  16. Python tab键命令补全
  17. Java并发编程:Java Thread方法join的简单总结
  18. [转帖] Kubernetes如何使用ReplicationController、Replica Set、Deployment管理Pod ----文章很好 但是还没具体操作实践 也还没记住.
  19. [C++] string与int, float, double相互转换
  20. 使用 php 7.3.0 官网的压缩包安装 FastAdmin

热门文章

  1. 人脸识别--SeetaFace
  2. 在开发板上显示英文字符和汉字--tiny6410
  3. offset()与position()的区别
  4. ATM管理系统
  5. 万字概览 Java 虚拟机
  6. Java中jna的用法
  7. TCP超时重传时间的选择
  8. pxe过程和原理
  9. Redis守护进程作用+数据类型
  10. 一文详解 ARP 协议