1、ES是如何实现分布式高并发全文检索
2、简单介绍ES分片Shards分片技术
3、为什么ES主分片对应的备分片不在同一台节点存放
4、索引的主分片定义好后为什么不能做修改
5、ES如何实现高可用容错方案
6、搭建Linux上环境三台ES高可用集群环境
7、基于ES网盘搜索引擎实现

网盘搜索引擎,写个Job 去网上爬虫 存储起来  以JSON的格式 存放在 ES服务器

网盘搜索引擎的原理:

采用ES存储抓取的数据 抓取服务器

测试数据:

##先创建索引PUT /clouddisk##测试数据mapingPOST /clouddisk/_mapping/disk
{"disk":{"properties":{"name":{"type":"text","analyzer":"ik_smart","search_analyzer":"ik_smart"},"source":{"type":"keyword"},"describe":{"type":"text","analyzer":"ik_smart","search_analyzer":"ik_smart"},"shartime":{"type":"date"},"browsetimes":{"type":"long"},"filesize":{"type":"float"},"sharpeople":{"type":"keyword"},"collectiontime":{"type":"date"},"baiduaddres":{"type":"keyword"}}}}POST /clouddisk/disk
{"name": "2018史上最全美剧","source": "百度云盘","describe": "该课程由小明提供","shartime": "2018-10-10","browsetimes": 100000,"filesize": 4.35,"sharpeople": "美国东部","collectiontime": "2018-11-24","baiduaddres": "https://pan.baidu.com/s/1VQxFq6JnKh0KP-5aMq-WpA#list/path=%2F"}POST /clouddisk/disk
{"name": "2018史上最全韩剧","source": "百度云盘","describe": "该课程小丽提供","shartime": "2018-10-12","browsetimes": 100000,"filesize": 6.35,"sharpeople": "韩国釜山","collectiontime": "2018-11-24","baiduaddres": "https://pan.baidu.com/s/1VQxFq6JnKh0KP-5aMq-WpA#list/path=%2F"}POST /clouddisk/disk
{"name": "老友记","source": "百度云盘","describe": "该课程由张三提供","shartime": "2018-10-10","browsetimes": 100000,"filesize": 1.35,"sharpeople": "美国","collectiontime": "2018-11-24","baiduaddres": "https://pan.baidu.com/s/1VQxFq6JnKh0KP-5aMq-WpA#list/path=%2F"}POST /clouddisk/disk
{"name": "英语雅思","source": "百度云盘","describe": "该课程由大海提供","shartime": "2018-10-10","browsetimes": 100000,"filesize": 1.35,"sharpeople": "大海","collectiontime": "2018-11-24","baiduaddres": "https://pan.baidu.com/s/1VQxFq6JnKh0KP-5aMq-WpA#list/path=%2F"}POST /clouddisk/disk
{"name": "小猪佩奇","source": "百度云盘","describe": "该课程由朱佩琦出品","shartime": "2018-10-10","browsetimes": 100000,"filesize": 1.35,"sharpeople": "佩奇","collectiontime": "2018-11-24","baiduaddres": "https://pan.baidu.com/s/1VQxFq6JnKh0KP-5aMq-WpA#list/path=%2F"}

maven:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.toov5</groupId><artifactId>springboot-esPan</artifactId><version>0.0.1-SNAPSHOT</version><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.0.0.RELEASE</version><relativePath /> <!-- lookup parent from repository --></parent><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-elasticsearch</artifactId></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></dependency><dependency><groupId>com.google.collections</groupId><artifactId>google-collections</artifactId><version>1.0-rc2</version></dependency><!-- springboot整合freemarker --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-freemarker</artifactId></dependency></dependencies></project>

Dao:

package com.toov5.dao;import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;import com.toov5.entity.CloudDiskEntity;public interface CloudDiskDao extends ElasticsearchRepository<CloudDiskEntity, String> {}

Entity:

package com.toov5.entity;import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;import lombok.Data;@Data
@Document(indexName = "clouddisk", type = "disk")
public class CloudDiskEntity {@Idprivate String id;// 名称private String name;// 来源private String source;// 描述private String describe;// 分享时间private String shartime;// 浏览次数private Long browsetimes;// 文件大小private Double filesize;// 分享人private String sharpeople;// 收录时间private String collectiontime;// 地址private String baiduaddres;}

Controller:

package com.toov5.controller;import java.util.List;
import java.util.Optional;import org.apache.commons.lang.StringUtils;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.MatchQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;import com.google.common.collect.Lists;
import com.toov5.dao.CloudDiskDao;
import com.toov5.entity.CloudDiskEntity;//SpringBoot 整合 ES

@RestController
public class CloudDiskController {@Autowiredprivate CloudDiskDao cloudDiskDao;@RequestMapping("/findById/{id}")public Optional<CloudDiskEntity> findById(@PathVariable String id) {Optional<CloudDiskEntity> findById = cloudDiskDao.findById(id);return  findById;}@RequestMapping("/search")public List<CloudDiskEntity> search(String keyWord,String describe) {//创建查询   查询所有的BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();   //创建查询if (!StringUtils.isEmpty(keyWord)) {//模糊查询  一定要用ik的中文分词插件!MatchQueryBuilder matchQuery = QueryBuilders.matchQuery("name", keyWord);boolQuery.must(matchQuery);}if (!StringUtils.isEmpty(describe)) {//模糊查询  一定要用ik的中文分词插件!MatchQueryBuilder matchQuery = QueryBuilders.matchQuery("describe", describe);boolQuery.must(matchQuery);}Iterable<CloudDiskEntity> search = cloudDiskDao.search(boolQuery); //查询所有的数据return Lists.newArrayList(search);  //通过这个api可以进行转换  //这样查询除了所有的 然后添加match
    }
}

yml:

spring:data:elasticsearch:####集群名称cluster-name: myes####地址 cluster-nodes: 192.168.91.7:9300freemarker:# 设置模板后缀名suffix: .ftl# 设置文档类型content-type: text/html# 设置页面编码格式charset: UTF-8# 设置页面缓存cache: false# 设置ftl文件路径template-loader-path:- classpath:/templates# 设置静态文件路径,js,css等mvc:static-path-pattern: /static/**

启动类:

package com.toov5;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;@SpringBootApplication
@EnableElasticsearchRepositories(basePackages="com.toov5.dao")   //dao 代码没有@Component的情况下可以这么玩儿 而且这样比较节省代码哈哈
public class AppEs {public static void main(String[] args) {SpringApplication.run(AppEs.class, args);
}
}

关键字查询时候,可以进行关键字查询,比like强悍!

分页查询: 很简单 传入参数 Pageable 就OK了  封装好了

GET /clouddisk/disk/_search
{"from": 0,"size":2,"query": {"match": {"name": "2018"}}}

page= 0 ,请求页数从0开始   2代表size 每一页代表多少条数据

前端传来参数是第几页

package com.toov5.controller;import java.util.List;
import java.util.Optional;import org.apache.commons.lang.StringUtils;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.MatchQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;import com.toov5.dao.CloudDiskDao;
import com.toov5.entity.CloudDiskEntity;//SpringBoot 整合 ES

@RestController
public class CloudDiskController {@Autowiredprivate CloudDiskDao cloudDiskDao;@RequestMapping("/findById/{id}")public Optional<CloudDiskEntity> findById(@PathVariable String id) {Optional<CloudDiskEntity> findById = cloudDiskDao.findById(id);return  findById;}@RequestMapping("/search")                  //写死了 默认值public Page<CloudDiskEntity> search(String keyWord,@PageableDefault(page=0,value=1) Pageable pageable) {//创建查询   查询所有的BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();   //创建查询if (!StringUtils.isEmpty(keyWord)) {//模糊查询  一定要用ik的中文分词插件!MatchQueryBuilder matchQuery = QueryBuilders.matchQuery("name", keyWord);boolQuery.must(matchQuery);}Page<CloudDiskEntity> search = cloudDiskDao.search(boolQuery,pageable);return search;}
}

访问:

也可以传入 页数 size数    

整合到前端展示:

Controller:

package com.toov5.controller;import javax.servlet.http.HttpServletRequest;import org.apache.commons.lang.StringUtils;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.MatchQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;import com.toov5.dao.CloudDiskDao;
import com.toov5.entity.CloudDiskEntity;@Controller
public class PageController {@Autowiredprivate CloudDiskDao cloudDiskDao;@RequestMapping("/search")                  //写死了 默认值public String search(String keyWord,@PageableDefault(page=0,value=2) Pageable pageable, HttpServletRequest req) {Long starTime = System.currentTimeMillis();//创建查询   查询所有的BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();   //创建查询if (!StringUtils.isEmpty(keyWord)) {//模糊查询  一定要用ik的中文分词插件!MatchQueryBuilder matchQuery = QueryBuilders.matchQuery("name", keyWord);boolQuery.must(matchQuery);}Page<CloudDiskEntity> page = cloudDiskDao.search(boolQuery,pageable);req.setAttribute("page", page);req.setAttribute("total", page.getTotalElements());req.setAttribute("keyword", keyWord);Long endTime = System.currentTimeMillis();req.setAttribute("time", endTime-starTime );return "search";}
}

页面展示:

页面:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head><meta charset="UTF-8"><title>Toov5|ES网盘搜索引擎</title><!-- 新 Bootstrap 核心 CSS 文件 --><link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"><!-- 可选的Bootstrap主题文件(一般不使用) --><script src="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap-theme.min.css"></script><!-- jQuery文件。务必在bootstrap.min.js 之前引入 --><script src="https://cdn.bootcss.com/jquery/2.1.1/jquery.min.js"></script><!-- 最新的 Bootstrap 核心 JavaScript 文件 --><script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script></head>
<body  style="display: block; margin: 0 auto; width: 50%; " ><div style="width:100%;height:60px;" align="center"><h2 style="color:#985f0d;">Toov5|ES网盘搜索引擎</h2></div><br/><div align="center"><span style="font-size: 18px;" >检索出${total}条数据,耗时:${time}毫秒</span></div><br/><br/><div class="bs-example" data-example-id="striped-table"><table class="table table-bordered table-hover"><thead><tr><th style="text-align:center;" scope="row">链接名称</th><th style="text-align:center;">文件大小GB</th><th style="text-align:center;">分享人</th><th style="text-align:center;">云盘地址</th></tr></thead><tbody><#list page.content as p><tr ><th style="text-align: left;" ><#if keyword??>${p.name?replace(keyword, '<span style="color: red">${keyword}</span>')}<#else>${p.name}</#if></th><th style="text-align: center;">${p.filesize}</th><th style="text-align: center;">${p.sharpeople}</th><th style="text-align: center;"><a href="${p.baiduaddres}">云盘地址</a> </th></tr></#list>    </tbody></table><!--    <div style="font-size: 21px;"><#list 1..totalPage as i>    <#if keyword??><a href="/search?keyword=${keyword}&page=${i-1}" >${i}</a><#else><a href="/search?page=${i-1}" >${i}</a></#if>     </#list>页</div>   --></div>
</body>
</html>

分页展示数据:

package com.toov5.controller;import javax.servlet.http.HttpServletRequest;import org.apache.commons.lang.StringUtils;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.MatchQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;import com.toov5.dao.CloudDiskDao;
import com.toov5.entity.CloudDiskEntity;@Controller
public class PageController {@Autowiredprivate CloudDiskDao cloudDiskDao;@RequestMapping("/search")                  //写死了 默认值public String search(String keyWord,@PageableDefault(page=0,value=2) Pageable pageable, HttpServletRequest req) {Long starTime = System.currentTimeMillis();//创建查询   查询所有的BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();   //创建查询if (!StringUtils.isEmpty(keyWord)) {//模糊查询  一定要用ik的中文分词插件!MatchQueryBuilder matchQuery = QueryBuilders.matchQuery("name", keyWord);boolQuery.must(matchQuery);}Page<CloudDiskEntity> page = cloudDiskDao.search(boolQuery,pageable);// 计算查询总数long total = page.getTotalElements();req.setAttribute("total", page.getTotalElements());// 计算分页数int totalPage = (int) ((total - 1) / pageable.getPageSize() + 1);req.setAttribute("totalPage", totalPage);req.setAttribute("page", page);req.setAttribute("total", page.getTotalElements());req.setAttribute("keyword", keyWord);Long endTime = System.currentTimeMillis();req.setAttribute("time", endTime-starTime );return "search";}
}

效果:

转载于:https://www.cnblogs.com/toov5/p/10296901.html

SpringBoot2.0+ElasticSearch网盘搜索实现相关推荐

  1. 搜集源码之github搜索语法,网盘搜索,搜索引擎等

    优雅地寻找网站源码(一) 0x0 前言 ​ 渗透过程中如果能获取到网站的源代码,那么无疑开启了上帝视角.虽然之前出现过不少通过搜索引擎查找同类网站,然后批量扫备份的思路,但是却没人分享其具体过程,这里 ...

  2. GUI小工具-网盘搜索器

    0. 写在最前 此专栏是记录以下一些我自己在本科写的一些小工具,仅仅用作学习为目的,绝不会有任何盈利,如果损害到了开发者的利益,请立即联系我进行删除,本人邮箱:zh00612@126.com 1. 介 ...

  3. 百度网盘搜索工具_2019

    百度网盘搜索工具 1.写在前面 经常搜索百度网盘里的资源,以前做了个数据来源来自盘多多,现在不能使用了.所以就又找了一个搜索网站史莱姆http://www.slimego.cn. 2.分析 通过获得查 ...

  4. [PHP] 网盘搜索引擎-采集爬取百度网盘分享文件实现网盘搜索

    标题起的太大了,都是骗人的.最近使用PHP实现了简单的网盘搜索程序,并且关联了微信公众平台.用户可以通过公众号输入关键字,公众号会返回相应的网盘下载地址.就是这么一个简单的功能,类似很多的网盘搜索类网 ...

  5. 【网盘搜索小程序完整源码】微信QQ双端通用

    本文转自:安好屋 本文链接:https://www.anhaowu.com/xcx/wangpanss.html ###一个微信QQ双端通用网盘搜索小程序 直接通过爬去第三方网站的搜索结果来实现搜索, ...

  6. [Android工具]更新安卓百度云盘百度网盘资源搜索工具,安卓网盘搜索软件

        更新一个网盘搜索工具:就叫"网盘搜索",之前发的叫"village"(山寨云) 网盘搜索的搜索源: 山寨云的搜索源: 山寨云: 功能:免费好用的网盘资源 ...

  7. [Android工具]安卓百度云盘百度网盘资源搜索工具,安卓网盘搜索软件

    功能:免费好用的网盘资源搜索工具. 下载:后台发送"百度网盘搜索"获取下载地址 不需要注册,不建议在此软件上登陆百度网盘(安全性未测试),建议只用这个软件搜索资源,然后复制资源链接 ...

  8. 这个网盘搜索好像还不错

    这个网盘搜索好像还不错 http://www.baiduyunpan.com/file/26474214.html 转载于:https://www.cnblogs.com/tujia/p/764964 ...

  9. python 百度云不限速_百度云不限速插件内置十几种网盘搜索!

    大家好,欢迎来到好软分享!度盘不限速,网盘搜索这种关键字大家不陌生吧,今天介绍一个厉害的神器,可以把这两个完美集合在一起,完爆其他任何软件 下面这个软件不陌生吧,目前为止还是最好用的百度云不限速工具, ...

最新文章

  1. Linux 学习日记 2: 目录结构和文件操作
  2. C#中实现对Excel特定文本的搜索
  3. 切换节点服务器网站,服务器手动切换节点
  4. 分布式系统概述(来自学习资料)
  5. 已知序列求蝶形运算_(数字信号处理选择题.doc
  6. 梯度下降法、最速下降法
  7. maven构建MyBatis项目
  8. [Toolkit]最新Silverlight Toolkit中的DragDrop支持
  9. 以太坊 ERC-20 ERC-721 ERC-1155区别对比
  10. 方正台式计算机保护卡密码忘记了,方正电脑E系列忘记还原卡密码处理方法
  11. [NOIP2016]回文日期
  12. 一篇文章,带你详细了解华为认证体系证书(1)
  13. matlab插值计算
  14. 关于安装VC++运行库遇到各种小问题
  15. Go:一次 exit code 是 137 且 无 coredump 的排错经历
  16. DICOM世界观·第一章 坐标系统
  17. 总结VUE控制滚动滑动方法
  18. 开发视频实时直播需要用到哪些技术?
  19. 夏普电视android应用程序,教你解决夏普电视出现的“应用程序未安装”问题
  20. 基于LVM的磁盘管理

热门文章

  1. python模拟抛硬币_关于概率:模拟2个人抛硬币直到获得第一个头像Python
  2. iOS基础-UIView
  3. html图片以烟花展现,HTML5花环式烟花绽放动画
  4. 百度提前批校园招聘开始啦!
  5. 99. Domino开发领域的动态
  6. win7计算机磁盘清理,如何清理win7计算机上的磁盘
  7. 晓看天色暮看云,行也思君,坐也思君。
  8. NodeJs 之模块系统
  9. 双十一养猫组队怎么退队
  10. 百度由来之众里寻他千百度