使用springboot整合elasticsearch+Vue实现数据查询

使用elasticsearch做数据服务查询:

实现springboot整合elasticsearchhe和vue做数据查询
注意:在进行此开发的时候一定要保证elasticsearch的版本与springboot的版本对应,否则可能会无法连接,这里用的elasticsearch和springboot的版本分别是5.6.16和2.2.1
elasticsearch仅支持1.8及1.8以上的jdk版本

开发工具

  • 后台开发:Idea;
  • 后台测试:Postman;
  • 前端开发:VScode;

elasticsearch服务搭建(Windows环境):

1、下载安装elasticsearch:官网地址

2、运行elasticsearch:

下载完解压即可:直接双击/bin/ElasticSearch.bat

使用springboot整合elasticsearch+Vue实现数据查询

4、安装node.js。

5、安装grunt-cli:

安装node.js的目录下,输入栏中输入cmd即可进入cmd命令操作符界面;
输入 npm install -g grunt-cli;
输入 grunt -version查看版本;
如果此时报错“grunt不是内部或外部命令,也不是可运行的程序 或批处理文件”,

解决方案:

①进入C:UsersAdministratorAppDataRoamingnpm,将此路径添加到环境变量PATH中。然后重新打开输入,依旧报错请执行第②步

②进入nodejs安装目录,将如下文件复制到C:UsersAdministratorAppDataRoamingnpm;然后进入nodejs的node_global目录,将grunt-cli和npm文件夹整体复制到C:Program Filesnodejsnode_globalnode_modules中。

6、安装elasticsearch-head:

安装:https://blog.csdn.net/mjlfto/article/details/79772848

另外一种方法,可通过谷歌的网上应用店进行下载安装elasticsearch-head到扩展程序即可(翻墙问题请自行解决)。

7、查看:

浏览器中输入:http://localhost:9100 查看,谷歌浏览器安装直接双击该扩展程序即可。

使用springboot整合elasticsearch+Vue实现数据查询

在解压的目录的bin目录下运行cmd输入 logstash -f logstash.conf。
注意:此工具不能停止运行,一旦停止运行,则无法实时同步数据库的数据!

9、elasticsearch-head连接elasticsearch服务端口进行数据查询:

使用springboot整合elasticsearch+Vue实现数据查询
elasticsearch服务器搭建完成。

后台开发:

如何搭建springboot项目请参考此博文,这里不再详细叙述:

以下是该项目的依赖及配置:

编写实体类:

@Document的作用
分页控制:

数据库对应实体:

dao编写:

service编写:

可省略service接口,且结构较为简单,这里不再贴出service的接口代码。

controller层编写:

package com.elasticsearch.web;import com.elasticsearch.pojo.Goods;import com.elasticsearch.pojo.SearchRequest;import com.elasticsearch.service.SearchService;import com.elasticsearch.utils.PageResult;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.http.ResponseEntity;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.PostMapping;import org.springframework.web.bind.annotation.RequestBody;import org.springframework.web.bind.annotation.RestController;import java.util.List;@RestControllerpublic class SearchController {    @Autowired    private SearchService searchService;    /*** 搜索功能* @param request* @return*/    @GetMapping("search")    public ResponseEntity来源:暮念朝兮
                                                        

声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2019年10月13日
下一篇 2019年10月13日

相关推荐