Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3647832
  • 博文数量: 365
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 2522
  • 用 户 组: 普通用户
  • 注册时间: 2019-10-28 13:40
文章分类

全部博文(365)

文章存档

2023年(8)

2022年(130)

2021年(155)

2020年(50)

2019年(22)

我的朋友

分类: Java

2021-01-08 17:12:39

单机:

spring:

    elasticsearch:

      rest:

        uris: [""]

        connection-timeout: 20s

        username: xxxxxxxx

        password: xxxxxxxxx

集群:

spring:

  data:

    elasticsearch:

      cluster-nodes: xxx.xxx.xx.3:9201,xxx.xxx.xx.3:9202,xxx.xxx.xx.4:9201,xxx.xxx.xx.4:9202

      cluster-name: xxxxxxxxxxx

  elasticsearch:

    rest:

      uris: [""]

      connection-timeout: 20s

      username: xxxxx

      password: xxxxxxxxxx

spingboot父依赖版本:

   

org.springframework.boot    

spring-boot-starter-parent

2.3.4.RELEASE

添加实体类映射:

package com.aipf.apply.esparam;

import lombok.AllArgsConstructor;import lombok.Data;import lombok.NoArgsConstructor;import org.springframework.data.elasticsearch.annotations.DateFormat;import org.springframework.data.elasticsearch.annotations.Document;import org.springframework.data.elasticsearch.annotations.Field;import org.springframework.data.elasticsearch.annotations.FieldType;import org.springframework.stereotype.Component;import java.util.Date;

@Data@AllArgsConstructor@NoArgsConstructor@Document(indexName = "two_tickets_ai_info")@Componentpublic class CameraNotice {    private Long id;    @Field(name = "@timestamp",type = FieldType.Date,format = DateFormat.custom,pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")    protected Date timestamp;  @Field(name = "in_cnt")    private int inCount;  @Field(name = "out_cnt")    private int outCount;@Field(name = "no_judge_cnt")    private int noJudgeCount;     @Field(name = "camera_id")    private Integer cameraId;

添加dao层操作对象

package com.aipf.apply.dao;

importcom.aipf.apply.esparam.CameraNotice;import org.springframework.data.elasticsearch.repository.ElasticsearchCrudRepository;

public interface CameraNoticeDao extends ElasticsearchCrudRepository {}

操作es

@Autowiredprivate CameraNoticeDao cameraNoticeDao;

CameraNotice cameraNotice = new CameraNotice();

cameraNoticeDao.save(cameraNotice); //es存入数据

阅读(21329) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~