您的位置:首页 > 编程语言 > Java开发

使用Logstash同步数据至Elasticsearch,Spring Boot中集成Elasticsearch实现搜索

2018-09-09 08:14 1186 查看

安装logstash、同步数据至ElasticSearch

为什么使用logstash来同步,CSDN上有一篇文章简要的分析了以下几种同步工具的优缺点:https://blog.csdn.net/laoyang360/article/details/51694519

下面开始实践:

  1. 下载Logstash 安装包,需要注意版本与elasticsearch保持一致,windows系统下直接解压即可。

  2.添加同步mysql数据库的配置,并将mysql连接驱动jar包放在指定的配置目录

    注: 目前版本的logstash已经集成了logstash-jdbc-input,不需要再配置这个插件,

       配置文件需要UTF-8编码,我在配置过程中开始新建文件默认的是GBK编码,后面启动logstash后读取配置文件报编码错误了。

我的配置目录:

@Controller
@RequestMapping("/blogs")
public class BlogController {

@Autowired
private IEsBlogService esBlogService;

@GetMapping
public String listBlogs(@RequestParam(value="order",required=false,defaultValue="new") String order,
@RequestParam(value="keyword",required=false,defaultValue="" ) String keyword,
@RequestParam(value="async",required=false) boolean async,
@RequestParam(value="pageIndex",required=false,defaultValue="0") int pageIndex,
@RequestParam(value="pageSize",required=false,defaultValue="5") int pageSize,
Model model) {
Pageable pageable = new PageRequest(pageIndex,pageSize);
Page<EsBlog> page = esBlogService.getEsBlogByKeys(keyword,pageable);
List<EsBlog> list  = page.getContent();
model.addAttribute("order", order);
model.addAttribute("keyword", keyword);
model.addAttribute("page", page);
model.addAttribute("blogList", list);
return (async==true?"/index :: #mainContainerRepleace":"/index");
}
}
View Code 演示效果:

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐