spring boot 使用 bboss 操作 ES
目前项目中将日志记录在ES中,就找了下比较简单的操作ES的方法找了好做最后选择用bboss,用起来太简单…
package com.td.tdgistaskservice.es.crud;import com.td.tdgistaskservice.es.entity.LoggerDemo;
import org.frameworkset.elasticsearch.ElasticSearchException;
import org.frameworkset.elasticsearch.boot.BBossESStarter;
import org.frameworkset.elasticsearch.client.ClientInterface;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;import java.text.ParseException;@Service
public class LoggerCrud {@Autowiredprivate BBossESStarter bbossESStarter;@Value("${es.indicename}")private String indicename;@Value("${es.esmapper}")private String esmapper;@Value("${es.createindicename}")private String createindicename;public void createIndice(){//创建加载配置文件的客户端工具,单实例多线程安全ClientInterface clientUtil = bbossESStarter.getConfigRestClient(esmapper);try {//判读索引表demo是否存在,存在返回true,不存在返回falseboolean exist = clientUtil.existIndice(indicename);//如果索引表demo已经存在先删除mappingif(exist) {return;/* clientUtil.dropIndice(indicename);clientUtil.existIndice(indicename);clientUtil.getIndice(indicename);//获取最新建立的索引表结构*/}//创建索引表democlientUtil.createIndiceMapping(indicename,createindicename);//索引表mapping dsl脚本名称,在esmapper/demo.xml中定义createDemoIndiceclientUtil.getIndice(indicename);//获取最新建立的索引表结构} catch (ElasticSearchException e) {// TODO Auto-generated catch blocke.printStackTrace();}}public void addAndUpdateDocument(LoggerDemo demo) throws ParseException {//创建创建/修改/获取/删除文档的客户端对象,单实例多线程安全ClientInterface clientUtil = bbossESStarter.getRestClient();clientUtil.addDocument(indicename,indicename, demo);}
}package com.td.tdgistaskservice.es.entity;import com.frameworkset.orm.annotation.ESId;
import lombok.Data;
import org.frameworkset.elasticsearch.entity.ESBaseData;@Data
public class LoggerDemo extends ESBaseData {//设定文档标识字段@ESIdprivate Long loggerid;private String loggercontent;/** 当在mapping定义中指定了日期格式时,则需要指定以下两个注解,例如*"agentStarttime": {"type": "date",###指定多个日期格式"format":"yyyy-MM-dd HH:mm:ss.SSS||yyyy-MM-dd'T'HH:mm:ss.SSS||yyyy-MM-dd HH:mm:ss||epoch_millis"}@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS")@Column(dataformat = "yyyy-MM-dd HH:mm:ss.SSS")*/private String agentStarttime;private String loggerlevel;private String loggermodel;
}<properties><!--创建demo需要的索引表结构--><property name="createloggerIndice"><![CDATA[{"settings": {"number_of_shards": 6,"index.refresh_interval": "5s"},"mappings": {"td_gis_logger": {"properties": {"loggerid":{"type":"long"},"loggercontent": {"type": "text"},"agentStarttime": {"type": "text"},"loggerlevel": {"type": "text"},"loggermodel": {"type": "text"}}}}}]]></property>
</properties>
配置文件
server:port: 9966
spring:http:multipart:max-file-size: 100Mbmax-request-size: 100Mbprofiles:active: developelasticsearch:bboss:elasticUser: elasticelasticPassword: changemeelasticsearch:rest:hostNames: 10.1.3.49:9200##hostNames: 192.168.8.25:9200,192.168.8.26:9200,192.168.8.27:9200 ##集群地址配置dateFormat: yyyy.MM.ddtimeZone: Asia/Shanghaittl: 2dshowTemplate: truediscoverHost: falsedslfile:refreshInterval: -1http:timeoutConnection: 5000timeoutSocket: 5000connectionRequestTimeout: 5000retryTime: 1maxLineLength: -1maxHeaderCount: 200maxTotal: 400defaultMaxPerRoute: 200soReuseAddress: falsesoKeepAlive: falsetimeToLive: 3600000keepAlive: 3600000keystore:keyPassword:hostnameVerifier:
spring boot 使用 bboss 操作 ES相关推荐
- springboot整合es_[ElasticSearch从入门到场景实战]spring boot集成SpringData操作es
人生起起伏伏,有风光无限日,也有落魄失魂时,人在低谷时,唯有"熬过去,才会赢" 前言 Elasticsearch的Spring Data是Spring Data项目的一部分,Spr ...
- 解决spring boot+JPA实现操作数据库时编辑时也变成了新增
场景:使用spring boot+JPA框架开发项目的时候,新增数据是正常的,但是编辑有时候会变成新增,JPA判断是否新增对象有两个方法:1根据id,2根据版本号.我在开发项目中用的是根据版本号进行判 ...
- Spring Boot 集成 Elasticsearch 实战
今天讲解下如何使用 Spring Boot 结合 ES. 可以在 ES 官方文档中发现,ES 为 Java REST Client 提供了两种方式的 Client:Java Low Level Cli ...
- ElasticSearch教程与实战:从搭建服务到Spring Boot整合
目录 写在前面 Elasticsearch是什么?可以解决什么问题? 关于Elasticsearch版本的选择 Elasticsearch的几个基本概念 索引(index) 类型(type) 文档(d ...
- 面试那点小事,你从未见过的spring boot面试集锦(附详细答案)
一, 什么是spring boot? 多年来,随着新功能的增加,spring变得越来越复杂.只需访问页面https://spring.io/projects,我们将看到所有在应用程序中使用的不同功能的 ...
- 如何优雅关闭 Spring Boot 应用
点击蓝色"程序猿DD"关注我 回复"资源"获取独家整理的学习资料! 前言 随着线上应用逐步采用 SpringBoot 构建,SpringBoot应用实例越来多, ...
- 精通spring——深入java ee开发核心技术 pdf_2019精通Spring Boot 42讲 高清pdf完整版
<精通springboot42讲价值99元入门到实教程>2019年最新spring boot教程,共计42讲从入门到精通,真正的实战教程. 课程内容和技术栈都会使⽤最新稳定版本,课程数量也 ...
- Spring Boot笔记-自动配置(Spring Boot封装成jar被其他项目引用)
特点: 这里也就是自己写个Service注册到别人的SpringBoot项目中,然后别人来调用这个Service,这个Service,先读取自己的application.properties,再读取引 ...
- Spring Boot JDBC 使用教程
总是要用到数据库的嘛,曾经我一度以为,写代码,编程就是搞数据库增删改查,甚至你设计一个系统,大部分时候在为如何设计关系型数据库努力,究其原因,是因为关系型数据库是逻辑的主要呈现. 这个系列,主要是对 ...
最新文章
- subprocess.Popen.stdout.readlines()
- 如何简单形象又有趣地讲解神经网络是什么?
- java rest框架_比较Java REST文档框架
- 调试九法(第1次阅读)
- qt获取场景的缩略图
- windows服务器远程执行命令(PowerShell+WinRM)
- koa源码分析-generator和yield分析
- Bootstrap3的简单入门
- Topcoder的使用方法
- NumPy库---拷贝
- Win10环境中运行Nacos2.0.4
- 陈希孺《概率论与数理统计》读书笔记
- 小恐龙游戏python_自动玩Chrome浏览器的小恐龙游戏
- JavaScript判断受访域名,调用不同的js文件
- html transition属性,Transition属性详解
- 倍福EK1110模块介绍
- Linux Glibc幽灵漏洞紧急修补方案【转】
- CTF小白新手导航(基础建议)
- 计算机网络学习笔记(一)——什么是Internet
- Eclipse中,代码没错,但有红叉叉
热门文章
- AWS SES发QQ邮箱拒收解决方案
- newifi路由器 php,newifi智能路由设置教程
- 生物信息学(3)——双序列比对之BLAST算法简介
- 5OSPF的邻居和NBMA环境下的邻居
- Microsoft Office 历史版本
- 使用SpringBoot一小时快速搭建一个简单后台管理(后端篇)
- Unity之线性渲染器
- 什么是散列表(Hash Table)
- jQuery 跨域访问问题解决方法
- c# websocket 心跳重连_初探和实现websocket心跳重连(npm: websocket-heartbeat-js) - 子慕大诗人 - 博客园...