最近项目中有文件信息需要快速索引,就打算把原来存储到MYSQL里面的数据全部存储到ES中
一下是代码
yml配置


```yaml
elasticsearch:bboss:elasticUser:elasticPassword:elasticsearch:rest:hostNames: 192.168.0.117:29200dateFormat: yyyy-MM-dd hh:mm:sstimeZone: Asia/Shanghaittl: 2dshowTemplate: truediscoverHost: falsedslfile:refreshInterval: -1http:timeoutConnection: 400000timeoutSocket: 400000connectionRequestTimeout: 400000retryTime: 1maxLineLength: -1maxHeaderCount: 200maxTotal: 400defaultMaxPerRoute: 200soReuseAddress: falsesoKeepAlive: falsetimeToLive: 3600000keepAlive: 3600000keystore:keyPassword:hostnameVerifier:
工具类
```java
package com.tudou.potato.datagaea.manager.emapper;import org.frameworkset.elasticsearch.ElasticSearchHelper;
import org.frameworkset.elasticsearch.client.ClientInterface;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;@Component
public class FileModelESMapper {public Logger logger = LoggerFactory.getLogger(FileModelESMapper.class);private static String mapper;private static ClientInterface restClient;private static ClientInterface restNoClient;public static ClientInterface restClient() {if (restClient == null) {restClient = ElasticSearchHelper.getConfigRestClientUtil(mapper);}return restClient;}public static ClientInterface restClientNoConfig() {if (restNoClient == null) {restNoClient = ElasticSearchHelper.getRestClientUtil();}return restNoClient;}@Value("${es.mappers.fileModel}")public void setMapper(String basePath) {FileModelESMapper.mapper = basePath;}
}

Service

package com.tudou.potato.datagaea.manager.repo;import com.tudou.potato.datagaea.manager.esentity.FileModel;
import com.tudou.potato.datagaea.manager.http.req.FileQuary;
import com.tudou.potato.datagaea.manager.http.req.FileQuaryPage;
import java.util.List;public interface FileStorageService {void insertFileModel(FileModel fileModel);FileModel searchFileModelByID(Integer id);void deleteFileModel(FileModel fileModel);List<FileModel> queryBaseSpotByPage(FileQuaryPage filepage);List<FileModel> selectByFileInfo(FileQuary params);
}package com.tudou.potato.datagaea.manager.repo.impl;import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.tudou.potato.datagaea.manager.emapper.FileModelESMapper;
import com.tudou.potato.datagaea.manager.esentity.FileModel;
import com.tudou.potato.datagaea.manager.http.req.FileQuary;
import com.tudou.potato.datagaea.manager.http.req.FileQuaryPage;
import com.tudou.potato.datagaea.manager.repo.FileStorageService;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.frameworkset.elasticsearch.client.ClientInterface;
import org.frameworkset.elasticsearch.entity.ESDatas;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;@Service
public class FileStorageServiceImpl implements FileStorageService {@Value("${es.function.fileModel.getById}")private String getById;@Value("${es.function.fileModel.createModel}")private String createModel;@Value("${es.function.fileModel.queryBaseSpotByPage}")private String queryBaseSpotByPage;@Value("${es.function.fileModel.selectByFileInfo}")private String selectByFileInfo;@Value("${es.index}")private String filemodel_index;@Value("${es.table}")private String table_str;@Overridepublic void insertFileModel(FileModel fileModel) {fileModel.setFileModelId(JSONObject.toJSONString(fileModel.getCollectData()).hashCode());ClientInterface basemapper = FileModelESMapper.restClient();if (!basemapper.existIndice(filemodel_index)) {basemapper.createIndiceMapping(filemodel_index, createModel);}//删除ID重复的数据basemapper.deleteDocument(filemodel_index, table_str, String.valueOf(fileModel.getFileModelId()));//新增docbasemapper.addDocument(filemodel_index, table_str, fileModel);}@Overridepublic FileModel searchFileModelByID(Integer id) {ClientInterface basemapper = FileModelESMapper.restClient();Map<String, java.lang.Object> paraMap = new HashMap<>();paraMap.put("id", id);ESDatas<FileModel> datas = basemapper.searchList(filemodel_index + "/_search", getById, paraMap, FileModel.class);return JSON.parseObject(JSON.toJSONString(datas.getDatas().get(0)), FileModel.class);}@Overridepublic void deleteFileModel(FileModel fileModel) {ClientInterface basemapper = FileModelESMapper.restClient();basemapper.deleteDocument(filemodel_index, table_str, String.valueOf(fileModel.getFileModelId()));}@Overridepublic List<FileModel> queryBaseSpotByPage(FileQuaryPage param) {ClientInterface basemapper = FileModelESMapper.restClient();ESDatas<FileModel> datas = basemapper.searchList(filemodel_index + "/_search", queryBaseSpotByPage, param, FileModel.class);return JSON.parseArray(JSON.toJSONString(datas.getDatas()), FileModel.class);}@Overridepublic List<FileModel> selectByFileInfo(FileQuary params) {ClientInterface basemapper = FileModelESMapper.restClient();ESDatas<FileModel> datas = basemapper.searchList(filemodel_index + "/_search", selectByFileInfo, params, FileModel.class);return JSON.parseArray(JSON.toJSONString(datas.getDatas()), FileModel.class);}
}

xml 实现

<properties><!--一个简单的检索dsl,中有四个变量name 全文检索字段startTimeendTime通过map传递变量参数值变量语法参考文档:https://my.oschina.net/bboss/blog/1556866--><property name="createfileModelIndice"><![CDATA[{"settings": {"number_of_shards": 6,"index.refresh_interval": "5s"},"mappings": {"file_model": {}}}]]></property><property name="queryBaseSpotByPage"><![CDATA[{"query": {"bool": {"must":[#if($workspaceId){ "match":{"workspaceId": $workspaceId}}#end#foreach($item in $collecParams.entrySet())#if($item.value),{   "match":{"collectData.$item.key": "$item.value"}}#end#end]}},## 分页起点"from":#[from],## 最多返回size条记录"size":#[pageSize]}]]></property><property name="selectByFileInfo"><![CDATA[{"query": {"bool": {"must":[#if($workspaceId){ "match":{ "workspaceId": $workspaceId } }#end#foreach($item in $collecParams.entrySet())#if($item.value),{"match": {  "collectData.$item.key": "$item.value" } }#end#end#if($storageType),{ "match":{  "fileLinkInfo.dataSourceType": "$storageType" } }#end]}}}]]></property><property name="searchFileModelByID"><![CDATA[{"query": {"match": {"fileModelId": #[id]}}}]]></property>
</properties>

Spring boot 中使用BBoss-ES进行ES的增删改查相关推荐

  1. Spring Boot 整合微信小程序实现登录与增删改查

    程序员的成长之路 互联网/程序员/技术/资料共享 关注 阅读本文大概需要 8 分钟. 作者:浮云骑士LIN cnblogs.com/ckfeng/p/12812214.html 项目描述:在微信小程序 ...

  2. 百词斩英语单词小助手(主要实现英语单词学习的功能。用户可对词典文件中的单词进行预览,增删改查。同时还可进行中英、英中测试。本系统还提供了测试成绩的显示功能。)

    struct word //单词的结构体 {char en[MAX_CHAR]; // 英文形式char ch[MAX_CHAR]; //中文形式 } s[MAX_NUM]; //单词数组 int n ...

  3. Python中对列表list进行定义、增删改查、遍历及与元组的对比

    https://blog.csdn.net/hanhanwanghaha宝藏女孩 欢迎您的关注! 欢迎关注微信公众号:宝藏女孩的成长日记 让这个可爱的宝藏女孩在努力的道路上与你一起同行! 如有转载,请 ...

  4. python diango 增删改查_python中关于django对数据库Mysql的增删改查操作详解

    下面小编就为大家带来一篇python django 增删改查操作 数据库Mysql.小编觉得挺不错的,现在就分享给大家,也给大家做个参考.一起跟随小编过来看看吧 下面介绍一下django增删改查操作: ...

  5. Spring+SpringMVC+Mybatis简单整合 图书管理项目 实现增删改查

    Spring+SpringMVC+Mybatis项目 tomcat7插件配置 <build><plugins><plugin><groupId>org. ...

  6. python numpy中对ndarry按照index(位置下标)增删改查

    在numpy中的ndarry是一个数组,因此index就是位置下标,注意下标是从0开始 增加:在插入时使用np.insert(),在末尾添加时使用np.append() 删除:需要使用np.delet ...

  7. myeclipse 实现框架 spring+springmvc+springsecurity+myibatis+mysql用户认证和人员增删改查

    一直想学习spring的框架结构和配置结构,利用周末借鉴诸多网友的精华,实现了下 1. 工具myeclipse 2. 框架springMVC+springSecurity+myibatis 3. 数据 ...

  8. uniCloud云函数中通过传统方式操作数据库的-增删改查

    云函数 可以看做java或者php,作为后端服务 cloudfunctions/myCloud/index.js exports.main = async (event, context) => ...

  9. 开发中最基本的对数据的增删改查SQL

    1.增加 insert   into   [表名] (列名) values(列值); 2.删除 delect  from  [表名]   [where<删除条件>] 3.修改 update ...

  10. Flex中Tree的用法备忘(增删改查节点)

    <?xml version="1.0" encoding="utf-8" ?> <mx:Application xmlns:mx=" ...

最新文章

  1. Puppet基础篇3-安装Puppet前期的准备工作
  2. Markdown 生成属于自己的电子书(pdf)
  3. 系统集成项目管理工程师-项目沟通管理笔记
  4. patent filter
  5. AI安检:北航提出安检场景下的危险品检测基准和去遮挡注意力模块
  6. div赋值,取值和input赋值,取值
  7. php中请写出定义变量的两种方法,php定义变量几种
  8. 易学源码html,HTML
  9. bat自动登录服务器取文件,批处理(.bat)一键备份资料,自动登录局域网进行备份,加~批处理.bat加密软件...
  10. 显著性水平 P值 概念解释
  11. and什么意思计算机SQL,SQL语句中 AND和OR的区别,or是什么意思,那and和它有什么区别?...
  12. 雍正杀“舅”:握着领导把柄,隆科多必须死?
  13. 如何制作自己的网页html,如何制作自己的网页
  14. 使用代理爬去微信公众号_微信公众号怎么去推广运营?企业微信公众号要如何运营?微信公众号运营技巧,你get了吗?微信怎么去推广运营?...
  15. 俄大神 lopatkin Windows 精简优化系统 - 工具软件
  16. 关于港澳通行证的办理和续签的问题总结
  17. Java简单的GUI考试系统
  18. Java OA集成SAP BO
  19. 利用nginx来屏蔽网页爬虫
  20. 基于Java汽车配件销售业绩管理系统设计实现(源码+lw+部署文档+讲解等)

热门文章

  1. 江西省2020年下半年中小学教师资格面试公告
  2. 地理国情监测,arcpy使用Select_analysis或者FeatureClassToFeatureClass_conversion将要素字段满足某一条件的要素提取出来。
  3. arcgis中判断某一字段值是否在list数组集合里(地理国情监测):
  4. SAP-ML章<<<<第一节:物料账报错处理>>>>2021-06-10
  5. 儿童编程:搭房子编程序-电脑小猫听我话
  6. python圣经是什么_GitHub标星6000+!Python带你实践机器学习圣经PRML
  7. STM32CubeMX配置SDRAM
  8. android epg界面实现,一种EPG引擎及页面解析方法与流程
  9. COMODO杀毒软件下载
  10. 常见数据结构-队列先进先出